To allow all components to be standalone and build for SSR in Angular using the still-supported ngExpressEngine
, here is the solution:
// in server.ts or main.server.ts (exported)
const _app = () => bootstrapApplication(AppComponent, {
providers: [
importProvidersFrom(ServerModule),
// add providers, interceptors, and all routes you want enabled on server
...CoreProviders,
// pass the routes from existing Routes used for browser
...AppRouteProviders
],
});
// in server.ts, nothing else changes
server.engine('html', ngExpressEngine({
bootstrap: _app
});
Let’s rant a bit about it: continue reading on Sekrab Garage.