Reputation: 329
I have two distinct Angular apps made with angular-cli, both already modified to run on a node.js server via Angular Universal following Angular's tutorial, but the example can only serve one app.
The example creates a view engine:
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');
Since each app has a different index.html
file, I'd need to create two view engines, but how can I tell Express to use one engine in one route and another engine in another route?
In other words, how can I map app1
to /app1
and app2
to /app2
?
Upvotes: 2
Views: 1329
Reputation: 222528
Express application can mount multiple sub-applications to different endpoints:
const app1 = express();
const app2 = express();
...
app.use('/app1', app1);
app.use('/app2', app2);
app.listen(3000);
Sub-applications can have their own settings and shouldn't be listen
ed.
Upvotes: 2