11// #docplaster
22
3- import { APP_BASE_HREF } from '@angular/common' ;
4- import { CommonEngine } from '@angular/ssr' ;
3+ import { APP_BASE_HREF } from '@angular/common' ;
4+ import { CommonEngine } from '@angular/ssr' ;
55import express from 'express' ;
6- import { fileURLToPath } from 'node:url' ;
7- import { dirname , join , resolve } from 'node:path' ;
6+ import { dirname , join , resolve } from 'node:path' ;
7+ import { fileURLToPath } from 'node:url' ;
8+
89import bootstrap from './src/main.server' ;
910
1011// The Express app is exported so that it can be used by serverless Functions.
@@ -13,42 +14,34 @@ export function app(): express.Express {
1314 const serverDistFolder = dirname ( fileURLToPath ( import . meta. url ) ) ;
1415 const browserDistFolder = resolve ( serverDistFolder , '../browser' ) ;
1516 const indexHtml = join ( serverDistFolder , 'index.server.html' ) ;
16- // #docregion CommonEngine
1717 const commonEngine = new CommonEngine ( ) ;
18- // #enddocregion CommonEngine
1918
2019 server . set ( 'view engine' , 'html' ) ;
2120 server . set ( 'views' , browserDistFolder ) ;
2221
23- // #docregion data-request
2422 // TODO: implement data requests securely
2523 // Serve data from URLS that begin "/api/"
2624 server . get ( '/api/**' , ( req , res ) => {
2725 res . status ( 404 ) . send ( 'data requests are not yet supported' ) ;
2826 } ) ;
29- // #enddocregion data-request
30- // #docregion static
3127 // Serve static files from /browser
32- server . get ( '*.*' , express . static ( browserDistFolder , {
33- maxAge : '1y'
34- } ) ) ;
35- // #enddocregion static
28+ server . get ( '*.*' , express . static ( browserDistFolder , { maxAge : '1y' } ) ) ;
3629
3730 // #docregion navigation-request
3831 // All regular routes use the Angular engine
3932 server . get ( '*' , ( req , res , next ) => {
40- const { protocol, originalUrl, baseUrl, headers } = req ;
33+ const { protocol, originalUrl, baseUrl, headers} = req ;
4134
4235 commonEngine
43- . render ( {
44- bootstrap,
45- documentFilePath : indexHtml ,
46- url : `${ protocol } ://${ headers . host } ${ originalUrl } ` ,
47- publicPath : browserDistFolder ,
48- providers : [ { provide : APP_BASE_HREF , useValue : req . baseUrl } ] ,
49- } )
50- . then ( ( html ) => res . send ( html ) )
51- . catch ( ( err ) => next ( err ) ) ;
36+ . render ( {
37+ bootstrap,
38+ documentFilePath : indexHtml ,
39+ url : `${ protocol } ://${ headers . host } ${ originalUrl } ` ,
40+ publicPath : browserDistFolder ,
41+ providers : [ { provide : APP_BASE_HREF , useValue : req . baseUrl } ] ,
42+ } )
43+ . then ( ( html ) => res . send ( html ) )
44+ . catch ( ( err ) => next ( err ) ) ;
5245 } ) ;
5346 // #enddocregion navigation-request
5447
0 commit comments