我有两个使用 angular-cli 制作的不同 Angular 应用程序,它们都已修改为通过 Angular Universal 在 Node.js 服务器上运行,如下 Angular's tutorial ,但该示例只能服务于一个应用程序。
该示例创建一个 View 引擎:
app.engine('html', (_, options, callback) => {
renderModuleFactory(AppServerModuleNgFactory, {
// Our index.html
document: template,
url: options.req.url,
// DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
extraProviders: [
provideModuleMap(LAZY_MODULE_MAP)
]
}).then(html => {
callback(null, html);
});
});
app.set('view engine', 'html');
由于每个应用程序都有不同的 index.html
文件,因此我需要创建两个 View 引擎,但如何告诉 Express 在一条 route 使用一个引擎,在另一条 route 使用另一个引擎?
换句话说,如何将 app1
映射到 /app1
并将 app2
映射到 /app2
?
最佳答案
Express应用程序可以挂载多个sub-applications到不同的端点:
const app1 = express();
const app2 = express();
...
app.use('/app1', app1);
app.use('/app2', app2);
app.listen(3000);
子应用程序可以有自己的设置,不应监听
。
关于angular - 在一个 Express 应用程序中提供多个 Angular Universal 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47213012/