@@ -5,38 +5,14 @@ import {
5
5
writeResponseToNodeResponse ,
6
6
} from '@angular/ssr/node' ;
7
7
import express from 'express' ;
8
- import { dirname , resolve } from 'node:path' ;
9
- import { fileURLToPath } from 'node:url' ;
8
+ import { dirname , join } from 'node:path' ;
9
+ import { fileURLToPath , pathToFileURL } from 'node:url' ;
10
10
11
- const serverDistFolder = dirname ( fileURLToPath ( import . meta. url ) ) ;
12
- const browserDistFolder = resolve ( serverDistFolder , '../browser' ) ;
11
+ const pathToSSRServer = pathToFileURL ( join ( dirname ( fileURLToPath ( import . meta. url ) ) , 'server.ssr.mjs' ) ) . toString ( )
13
12
14
13
const app = express ( ) ;
15
14
const angularApp = new AngularNodeAppEngine ( ) ;
16
15
17
- /**
18
- * Example Express Rest API endpoints can be defined here.
19
- * Uncomment and define endpoints as necessary.
20
- *
21
- * Example:
22
- * ```ts
23
- * app.get('/api/**', (req, res) => {
24
- * // Handle API request
25
- * });
26
- * ```
27
- */
28
-
29
- /**
30
- * Serve static files from /browser
31
- */
32
- app . use (
33
- express . static ( browserDistFolder , {
34
- maxAge : '1y' ,
35
- index : false ,
36
- redirect : false ,
37
- } )
38
- ) ;
39
-
40
16
/**
41
17
* Handle all other requests by rendering the Angular application.
42
18
*/
@@ -53,7 +29,7 @@ app.use('/**', (req, res, next) => {
53
29
* Start the server if this module is the main entry point.
54
30
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
55
31
*/
56
- if ( isMainModule ( import . meta . url ) ) {
32
+ if ( isMainModule ( pathToSSRServer ) ) {
57
33
const port = process . env [ 'PORT' ] || 4000 ;
58
34
app . listen ( port , ( ) => {
59
35
console . log ( `Node Express server listening on http://localhost:${ port } ` ) ;
0 commit comments