Files
accounted/lib/domains/legacy-redirect.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

26 lines
1.2 KiB
TypeScript

/**
* Path exclusions for the legacy-host (app.gnubok.se) page redirect in
* next.config.ts.
*
* Machine surfaces (api/, .well-known/), assets (_next/) and the
* PKCE-cookie-bound auth flows (auth/, reset-password) must keep answering
* on the legacy host after the app.accounted.se cutover; everything else
* forwards to the new domain. auth/ and reset-password stay because email
* links sent before the cutover carry a PKCE code or recovery session
* whose cookies live on the legacy host (#1092); the login and MFA pages
* are deliberately NOT excluded, since a usable login page on the legacy
* host would establish sessions there and bounce users in a redirect loop.
*/
export const LEGACY_HOST_REDIRECT_EXCLUSIONS =
'(?!api/|\\.well-known/|_next/|auth/|reset-password)'
/**
* Mirror of how the path-to-regexp source `/:path((?!...).*)` decides
* whether a legacy-host request is forwarded. Used by tests to pin the
* exclusion behavior without booting Next's router.
*/
export function isRedirectedFromLegacyHost(pathname: string): boolean {
const relative = pathname.replace(/^\//, '')
return new RegExp(`^${LEGACY_HOST_REDIRECT_EXCLUSIONS}.*$`).test(relative)
}