From 7292000cfa87dfc4626e584ffa52a9651fded582 Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Thu, 21 Mar 2024 08:55:03 +0530 Subject: [PATCH] fix: handle trailing slashes for prerendered files (#5) --- src/server.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 5d05ce9..4bcd690 100644 --- a/src/server.ts +++ b/src/server.ts @@ -20,6 +20,10 @@ async function* getPrerenderedFiles(clientRoot: URL): AsyncGenerator { } } +function removeTrailingForwardSlash(path: string) { + return path.endsWith('/') ? path.slice(0, path.length - 1) : path; +} + export function start(manifest: SSRManifest, options: Options) { if (options.start === false) { return; @@ -52,7 +56,7 @@ export function start(manifest: SSRManifest, options: Options) { let fallback; for await (const file of getPrerenderedFiles(clientRoot)) { const pathname = file.pathname.replace(/\/(index)?\.html$/, ''); - if (localPath.pathname.endsWith(pathname)) { + if (removeTrailingForwardSlash(localPath.pathname).endsWith(pathname)) { fallback = file; break; }