feat(i18n): nl at root URLs + keep devtools in the docker demo

Serve the source locale (nl) at / instead of /nl/: angular.json sourceLocale is now
{ code: 'nl', subPath: '' } → nl output at browser/ root (base href /), en stays /en/.
Rework localeLinks (nl → bare path, en → /en/…) + spec, and serve-i18n.mjs (nl assets at
root, en under /en/, / serves the nl index). And build the docker demo (+ serve:i18n) with
`--configuration development --localize` so isDevMode() stays true and the dev `⚙ state`
panel + role/scenario switchers render in the localized compose demo (they were correctly
gated off in the previous production build). Verified: nl base href /, en /en/, ngDevMode present.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
eho
2026-07-23 19:24:33 +02:00
co-authored by Claude Opus 4.8
parent deb5d77e04
commit c00e607b8f
6 changed files with 35 additions and 31 deletions
+7 -9
View File
@@ -52,25 +52,23 @@ createServer(async (req, res) => {
return;
}
const url = decodeURIComponent(rawUrl.split('?')[0]);
// Landing at / has no locale bundle — redirect to Dutch.
if (url === '/') {
res.writeHead(302, { location: '/nl/' });
return res.end();
}
const rel = normalize(url).replace(/^(\.\.[/\\])+/, ''); // no path traversal
const locale = url.startsWith('/en/') ? 'en' : 'nl';
// nl (source) is served at the ROOT (subPath ''); en lives under /en/.
const isEn = url === '/en' || url.startsWith('/en/');
const indexPath = isEn ? join(ROOT, 'en', 'index.html') : join(ROOT, 'index.html');
try {
// A real asset (nl at root, en under /en/) — otherwise fall through to the SPA index.
if (url === '/' || url === '/en' || url === '/en/') throw new Error('serve index');
const file = await readFile(join(ROOT, rel));
send(res, 200, file, MIME[extname(rel)] ?? 'application/octet-stream');
} catch {
// SPA fallback to the requested locale's index.html.
try {
const index = await readFile(join(ROOT, locale, 'index.html'));
send(res, 200, index, 'text/html');
send(res, 200, await readFile(indexPath), 'text/html');
} catch {
send(res, 404, 'Not found', 'text/plain');
}
}
}).listen(PORT, () => {
console.log(`Serving ${ROOT} at http://localhost:${PORT}/ (→ /nl/, /en/)`);
console.log(`Serving ${ROOT} at http://localhost:${PORT}/ (nl at /, en at /en/)`);
});