Open History to see the last commit
1import {
2 AngularNodeAppEngine,
3 createNodeRequestHandler,
4 isMainModule,
5 writeResponseToNodeResponse,
6} from '@angular/ssr/node'
7import express from 'express'
8import { join } from 'node:path'
9β
10const browserDistFolder = join(import.meta.dirname, '../browser')
11β
12const app = express()
13const angularApp = new AngularNodeAppEngine()
14β
15app.use(
16 express.static(browserDistFolder, {
17 maxAge: '1y',
18 index: false,
19 redirect: false,
20 }),
21)
22β
23app.use((req, res, next) => {
24 angularApp
25 .handle(req)
26 .then((response) =>
27 response ? writeResponseToNodeResponse(response, res) : next(),
28 )
29 .catch(next)
30})
31β
32if (isMainModule(import.meta.url)) {
33 const port = process.env['PORT'] || 4000
34 app.listen(port, (error) => {
35 if (error) {
36 throw error
37 }
38β
39 console.log(`Node Express server listening on http://localhost:${port}`)
40 })
41}
42β
43export const reqHandler = createNodeRequestHandler(app)