fix(ssr): enable static route rendering and fix self-import in server.ts
CI Pipeline / backend-test (push) Successful in 9m12s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 30s
CI Pipeline / backend-lint (push) Successful in 9s
CI Pipeline / backend-test (pull_request) Successful in 10m0s
CI Pipeline / frontend-test (pull_request) Successful in 23s
CI Pipeline / frontend-build (pull_request) Successful in 30s
CI Pipeline / backend-lint (pull_request) Successful in 9s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 2s
CI Pipeline / backend-test (push) Successful in 9m12s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 30s
CI Pipeline / backend-lint (push) Successful in 9s
CI Pipeline / backend-test (pull_request) Successful in 10m0s
CI Pipeline / frontend-test (pull_request) Successful in 23s
CI Pipeline / frontend-build (pull_request) Successful in 30s
CI Pipeline / backend-lint (pull_request) Successful in 9s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 2s
- Add AngularAppEngine.ɵallowStaticRouteRender flag so the engine serves prerendered static HTML from disk instead of falling back to SSR - Rename default export to named const (requestHandler) to avoid self-import loop when the module is the entry point - Use requestHandler directly in the main-module listener instead of importing './server.js' which caused TS2307 resolution failure
This commit is contained in:
1 parent
63bc2fb22d
commit
a8b6e65831
1 file changed
+9
-3
@@ -4,8 +4,13 @@ import {
|
|||||||
isMainModule,
|
isMainModule,
|
||||||
writeResponseToNodeResponse,
|
writeResponseToNodeResponse,
|
||||||
} from '@angular/ssr/node';
|
} from '@angular/ssr/node';
|
||||||
|
import { AngularAppEngine } from '@angular/ssr';
|
||||||
import * as http from 'node:http';
|
import * as http from 'node:http';
|
||||||
|
|
||||||
|
// Enable serving prerendered static HTML from disk. Without this flag the
|
||||||
|
// engine falls back to SSR for every route, ignoring the prerendered output.
|
||||||
|
AngularAppEngine.ɵallowStaticRouteRender = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public routes prerendered at build time (SSG — Static Site Generation).
|
* Public routes prerendered at build time (SSG — Static Site Generation).
|
||||||
* These five routes are compiled to static HTML during `ng build` and
|
* These five routes are compiled to static HTML during `ng build` and
|
||||||
@@ -53,7 +58,7 @@ function getEngine(): AngularNodeAppEngine {
|
|||||||
* as pre-generated static HTML from the build output. All other routes
|
* as pre-generated static HTML from the build output. All other routes
|
||||||
* fall back to server-side rendering (SSR) or the fallback 404 handler.
|
* fall back to server-side rendering (SSR) or the fallback 404 handler.
|
||||||
*/
|
*/
|
||||||
export default createNodeRequestHandler(async (req, res, next) => {
|
const requestHandler = createNodeRequestHandler(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const prerendered = isPrerenderedRoute(req.url || '/');
|
const prerendered = isPrerenderedRoute(req.url || '/');
|
||||||
if (prerendered) {
|
if (prerendered) {
|
||||||
@@ -76,11 +81,12 @@ export default createNodeRequestHandler(async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default requestHandler;
|
||||||
|
|
||||||
if (isMainModule(import.meta.url)) {
|
if (isMainModule(import.meta.url)) {
|
||||||
const httpServer = http.createServer();
|
const httpServer = http.createServer();
|
||||||
httpServer.on('request', async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
httpServer.on('request', async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
const handler = (await import('./server.js')).default;
|
requestHandler(req, res, () => {
|
||||||
handler(req, res, () => {
|
|
||||||
res.statusCode = 404;
|
res.statusCode = 404;
|
||||||
res.end('Not Found');
|
res.end('Not Found');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user