Fix MPM root route redirect loop

This commit is contained in:
Kühn
2026-10-08 15:22:47 +02:00
parent 9b22d2ed7d
commit 975345f8b1

View File

@@ -28,7 +28,11 @@ const server = createModuleServer({
logger, logger,
identityRequired: true, identityRequired: true,
routes(request, response, context) { routes(request, response, context) {
const targetPath = `${basePath}${context.url.pathname}${context.url.search}`; // Next.js treats the configured base path itself as the canonical root
// (without a trailing slash). Keep `/kalendartool` stable when MPM routes
// an incoming `/kalendartool` request as the module path `/`.
const modulePath = context.url.pathname === '/' ? '' : context.url.pathname;
const targetPath = `${basePath}${modulePath}${context.url.search}`;
const headers = { ...request.headers, host: `127.0.0.1:${nextPort}` }; const headers = { ...request.headers, host: `127.0.0.1:${nextPort}` };
for (const name of Object.keys(headers)) { for (const name of Object.keys(headers)) {
if (name.startsWith('x-kalendartool-mpm-')) delete headers[name]; if (name.startsWith('x-kalendartool-mpm-')) delete headers[name];