Skip to content

Commit d308467

Browse files
committed
fix: add angular-20 server.ts signature
1 parent c98527c commit d308467

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/helpers/knownServerTsSignatures.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"33d360cdf4819d90afeecd49952241191ee490900fa919a46f990186be3e8b5f": "CommonEngine",
88
"140c0a0b4a8b648378d53630bee6bef9c3418daf27b372f50c06ab83c9d84a39": "CommonEngine",
99
"76419eb94b4b8672ba3bd79d34c5a66c7c30ff173995ecc6e0adc5808b86822d": "AppEngine",
10+
"8fc83d8961c0a74b52e2dc90f8f6bc21a6948ca35fda4b83ff063ae441d42c11": "AppEngine",
1011
"a5aad843a116e34ce61264117cba981cff5eea3e6672815a4db08e7b4e5599d6": "AppEngine",
1112
"5e0de282eb33582f8ec4c3da2946762d4c95794cb749cfb589407f4d4a0115a7": "AppEngine"
1213
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
AngularNodeAppEngine,
3+
createNodeRequestHandler,
4+
isMainModule,
5+
writeResponseToNodeResponse,
6+
} from '@angular/ssr/node';
7+
import express from 'express';
8+
import { join } from 'node:path';
9+
10+
const browserDistFolder = join(import.meta.dirname, '../browser');
11+
12+
const app = express();
13+
const angularApp = new AngularNodeAppEngine();
14+
15+
/**
16+
* Example Express Rest API endpoints can be defined here.
17+
* Uncomment and define endpoints as necessary.
18+
*
19+
* Example:
20+
* ```ts
21+
* app.get('/api/{*splat}', (req, res) => {
22+
* // Handle API request
23+
* });
24+
* ```
25+
*/
26+
27+
/**
28+
* Serve static files from /browser
29+
*/
30+
app.use(
31+
express.static(browserDistFolder, {
32+
maxAge: '1y',
33+
index: false,
34+
redirect: false,
35+
}),
36+
);
37+
38+
/**
39+
* Handle all other requests by rendering the Angular application.
40+
*/
41+
app.use((req, res, next) => {
42+
angularApp
43+
.handle(req)
44+
.then((response) =>
45+
response ? writeResponseToNodeResponse(response, res) : next(),
46+
)
47+
.catch(next);
48+
});
49+
50+
/**
51+
* Start the server if this module is the main entry point.
52+
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
53+
*/
54+
if (isMainModule(import.meta.url)) {
55+
const port = process.env['PORT'] || 4000;
56+
app.listen(port, (error) => {
57+
if (error) {
58+
throw error;
59+
}
60+
61+
console.log(`Node Express server listening on http://localhost:${port}`);
62+
});
63+
}
64+
65+
/**
66+
* Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions.
67+
*/
68+
export const reqHandler = createNodeRequestHandler(app);

0 commit comments

Comments
 (0)