import { APP_ID } from '@angular/core'; import { bootstrapApplication, BootstrapContext } from '@angular/platform-browser'; import { provideServerRendering, withRoutes } from '@angular/ssr'; import { appConfig } from './app/app.config'; import { App } from './app/app'; import { APP_CONFIG, AppConfig } from './app/services/app-config.service'; import { serverRoutes } from './app/app.server.routes'; // During SSR, the API base URL must be absolute (HttpClient runs in Node.js). // nginx proxies /api/ to the upstream, so point at nginx (port 80) locally. const ssrApiBaseUrl = process.env['SSR_API_BASE_URL'] || 'http://localhost:80'; const ssrAppConfig: AppConfig = { apiBaseUrl: ssrApiBaseUrl }; const serverAppConfig = { ...appConfig, providers: [ ...appConfig.providers, { provide: APP_ID, useValue: 'server' }, { provide: APP_CONFIG, useValue: ssrAppConfig }, provideServerRendering(withRoutes(serverRoutes)), ], }; /** * Bootstrap function for server-side rendering. * Exports a function that accepts BootstrapContext and returns ApplicationRef, * as required by @angular/ssr's CommonEngine bootstrap signature. */ export default (ctx: BootstrapContext) => bootstrapApplication(App, serverAppConfig, ctx);