Skip to content

Commit

Permalink
fix: handle trailing slashes for prerendered files (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy authored Mar 21, 2024
1 parent 7fc1a15 commit 7292000
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ async function* getPrerenderedFiles(clientRoot: URL): AsyncGenerator<URL> {
}
}

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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7292000

Please sign in to comment.