Files
kmtnflower/server.ts
T
DevOps QA 1db84a384f
CI Pipeline / backend-test (push) Successful in 9m49s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 30s
CI Pipeline / backend-lint (push) Successful in 8s
CI Pipeline / backend-test (pull_request) Successful in 9m38s
CI Pipeline / frontend-test (pull_request) Successful in 23s
CI Pipeline / frontend-build (pull_request) Successful in 31s
CI Pipeline / backend-lint (pull_request) Successful in 10s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 3s
fix(ssr): manually register engine manifest to fix 404 on all routes
The Angular 21 builder generates angular-app-engine-manifest.mjs at build
time but does NOT inject the import into server.mjs. Without manually
importing and registering the manifest via ɵsetAngularAppEngineManifest,
AngularNodeAppEngine fails with 'Angular app engine manifest is not set'
and every request returns 404.

This matches the exact issue reported in PR #14 on staging where nginx
starts successfully but returns 'Not Found' for all paths.
2026-08-07 19:02:10 +00:00

58 lines
1.6 KiB
TypeScript

import {
AngularNodeAppEngine,
createNodeRequestHandler,
isMainModule,
writeResponseToNodeResponse,
} from '@angular/ssr/node';
import * as http from 'node:http';
/**
* Manually import and register the Angular app engine manifest.
* The Angular 21 builder generates angular-app-engine-manifest.mjs at build time
* but does NOT automatically inject the import into server.mjs.
* Without this, AngularNodeAppEngine fails with "Angular app engine manifest is not set"
* and every SSR request returns 404.
*/
// @ts-ignore — generated at build time by @angular/build
import engineManifest from './angular-app-engine-manifest.mjs';
import { ɵsetAngularAppEngineManifest } from '@angular/ssr';
ɵsetAngularAppEngineManifest(engineManifest);
const appEngine = new AngularNodeAppEngine();
const requestHandler = createNodeRequestHandler(async (req, res, next) => {
try {
const response = await appEngine.handle(req);
if (response) {
await writeResponseToNodeResponse(response, res);
} else {
next();
}
} catch (error) {
next(error);
}
});
if (isMainModule(import.meta.url)) {
console.log('Node.js SSR server ready');
const server = http.createServer();
server.on('request', async (req, res) => {
try {
await requestHandler(req, res, () => {
res.statusCode = 404;
res.end('Not Found');
});
} catch (error) {
console.error('SSR error:', error);
res.statusCode = 500;
res.end('Internal server error');
}
});
server.listen(4200, () => {
console.log('SSR server listening on http://localhost:4200');
});
}
export { requestHandler };