我有一个角度通用的应用程序。当使用以下命令直接从节点(localhost:4000)运行时,所有操作都能正常工作: npm run build:ssr npm run serve:ssr
对于生产环境,我需要在子路径(servername/appname)而不是根目录下为应用程序提供服务。The服务器是apache,我按如下方式使用代理: proxypass "/appname/“"http://localhost:4000/”
现在来看问题:对于SSR,baseref是“/”,但对于客户端渲染,baseref是“/appname”。这意味着,在根目录上使用node/express的SSR或在servername/appname上运行应用程序的客户端无法找到index.html (main.js等)中链接的文件。
是否有可能为SSR和CSR提供不同的基础?
我能想到的一个办法是在“localhost:4000/appname”…上托管SSR-app。但是我不知道如何在我的server.ts…中配置它
任何帮助都非常感谢!
发布于 2019-05-16 19:32:55
至少我现在让节点在相同的href下运行SSR-app
const allowed = [
'.js',
'.css',
'.png',
'.jpg',
'.svg',
'.woff',
'.ttf'
];
const disallowed = [
'.map'
]
app.get('/appname/*', (req, res) => {
if (allowed.filter(ext => req.url.indexOf(ext) > 0).length > 0 && disallowed.filter(ext => req.url.indexOf(ext) > 0).length == 0) {
res.sendFile(resolve(DIST_FOLDER + req.url.replace("appname/", "")));
} else {
res.render('index', {req})
//res.sendFile(path.join(__dirname, 'client/dist/client/index.html'));
}
});https://stackoverflow.com/questions/56166312
复制相似问题