1
1
import { APP_BASE_HREF } from '@angular/common' ;
2
- import { CommonEngine , isMainModule } from '@angular/ssr/node' ;
2
+ import { CommonEngine , createNodeRequestHandler , isMainModule } from '@angular/ssr/node' ;
3
3
import express from 'express' ;
4
4
import { dirname , join , resolve } from 'node:path' ;
5
5
import { fileURLToPath } from 'node:url' ;
@@ -9,7 +9,7 @@ const serverDistFolder = dirname(fileURLToPath(import.meta.url));
9
9
const browserDistFolder = resolve ( serverDistFolder , '../browser' ) ;
10
10
const indexHtml = join ( serverDistFolder , 'index.server.html' ) ;
11
11
12
- const app = express ( ) ;
12
+ const server = express ( ) ;
13
13
const commonEngine = new CommonEngine ( ) ;
14
14
15
15
/**
@@ -27,7 +27,7 @@ const commonEngine = new CommonEngine();
27
27
/**
28
28
* Serve static files from /browser
29
29
*/
30
- app . get (
30
+ server . get (
31
31
'**' ,
32
32
express . static ( browserDistFolder , {
33
33
maxAge : '1y' ,
@@ -38,7 +38,7 @@ app.get(
38
38
/**
39
39
* Handle all other requests by rendering the Angular application.
40
40
*/
41
- app . get ( '**' , ( req , res , next ) => {
41
+ server . get ( '**' , ( req , res , next ) => {
42
42
const { protocol, originalUrl, baseUrl, headers } = req ;
43
43
44
44
commonEngine
@@ -59,7 +59,21 @@ app.get('**', (req, res, next) => {
59
59
*/
60
60
if ( isMainModule ( import . meta. url ) ) {
61
61
const port = process . env [ 'PORT' ] || 4000 ;
62
- app . listen ( port , ( ) => {
62
+ server . listen ( port , ( ) => {
63
63
console . log ( `Node Express server listening on http://localhost:${ port } ` ) ;
64
64
} ) ;
65
65
}
66
+
67
+ /** workaround **/
68
+ // using the suggestion from the documentation: https://angular.dev/guide/hybrid-rendering#configuring-a-nodejs-server
69
+
70
+ // export const reqHandler = createNodeRequestHandler(app);
71
+
72
+ // doesn't work, this would be on the firebase-tools side at:
73
+ // - see https://github.com/firebase/firebase-tools/pull/8145
74
+ // - see https://github.com/firebase/firebase-tools/pull/8145/commits/6bfdff095902c9ec469d6fe8c82223987e43e213
75
+
76
+ /**
77
+ * The request handler used by the Angular CLI (dev-server and during build).
78
+ */
79
+ export const app = ( ) => createNodeRequestHandler ( server ) ;
0 commit comments