fix(ssr): apply theme CSS vars during SSR and enable client hydration
CI Pipeline / backend-test (push) Successful in 9m4s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 32s
CI Pipeline / backend-lint (push) Successful in 14s
CI Pipeline / backend-test (pull_request) Successful in 9m17s
CI Pipeline / frontend-test (pull_request) Successful in 24s
CI Pipeline / frontend-build (pull_request) Successful in 30s
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 2s
CI Pipeline / backend-test (push) Successful in 9m4s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 32s
CI Pipeline / backend-lint (push) Successful in 14s
CI Pipeline / backend-test (pull_request) Successful in 9m17s
CI Pipeline / frontend-test (pull_request) Successful in 24s
CI Pipeline / frontend-build (pull_request) Successful in 30s
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 2s
- ThemeService: remove isPlatformBrowser guard so CSS custom properties are applied during SSR/prerender — server-rendered HTML now carries the correct color scheme and gradients (fixes missing colors on test site). - main.ts: add provideClientHydration() so Angular preserves the server- rendered DOM on the client instead of destroying and rebuilding it (fixes jarring full-page reload between static and dynamic versions). - Tests: update theme.service.spec.ts to match new behaviour, expand coverage with gradient tests and empty-value handling (9 tests). Fix structured-data.component.spec.ts import paths. All 54 tests pass.
This commit is contained in:
1 parent
2d26269c1a
commit
e95a158d57
10 files changed
+551
-16
No files matched your search
@@ -6,16 +6,53 @@ import {
|
||||
} from '@angular/ssr/node';
|
||||
import * as http from 'node:http';
|
||||
|
||||
/**
|
||||
* Public routes prerendered at build time (SSG — Static Site Generation).
|
||||
* These five routes are compiled to static HTML during `ng build` and
|
||||
* served directly from disk at runtime for optimal performance and SEO.
|
||||
* The list here mirrors `prerender-routes.txt` and the Prerender entries
|
||||
* in `src/app/app.server.routes.ts`.
|
||||
*/
|
||||
export const PRERENDERED_ROUTES: readonly string[] = [
|
||||
'/',
|
||||
'/about',
|
||||
'/schedule',
|
||||
'/events',
|
||||
'/contact',
|
||||
];
|
||||
|
||||
const ngApp = new AngularNodeAppEngine();
|
||||
|
||||
/**
|
||||
* Normalise a request pathname and check against prerendered routes.
|
||||
* Handles both bare paths (`/about`) and trailing-slash variants (`/about/`).
|
||||
*/
|
||||
export function isPrerenderedRoute(url: string): boolean {
|
||||
const pathname = new URL(url, 'http://localhost').pathname;
|
||||
const normalised = pathname.endsWith('/') && pathname !== '/'
|
||||
? pathname.slice(0, -1)
|
||||
: pathname;
|
||||
return PRERENDERED_ROUTES.includes(normalised);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming requests using the Angular SSR engine.
|
||||
* Prerendered routes are served as static HTML at build time.
|
||||
* Dynamic routes fall back to server-side rendering.
|
||||
*
|
||||
* Prerendered routes (/ , /about, /schedule, /events, /contact) are served
|
||||
* as pre-generated static HTML from the build output. All other routes
|
||||
* fall back to server-side rendering (SSR) or the fallback 404 handler.
|
||||
*/
|
||||
export default createNodeRequestHandler(async (req, res, next) => {
|
||||
try {
|
||||
const prerendered = isPrerenderedRoute(req.url || '/');
|
||||
if (prerendered) {
|
||||
// Prerendered routes are served as static HTML — AngularNodeAppEngine
|
||||
// reads the build-time manifest and returns the pre-generated response.
|
||||
console.log(`[SSR] Prerendered route: ${req.url}`);
|
||||
}
|
||||
|
||||
const response = await ngApp.handle(req);
|
||||
|
||||
if (response) {
|
||||
await writeResponseToNodeResponse(response, res);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user