Skip to content

Commit

Permalink
Remove extension name check when generating response
Browse files Browse the repository at this point in the history
* Fix #2779
  • Loading branch information
taoky committed Sep 28, 2023
1 parent 78e9397 commit 41294df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/cold-bugs-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/pages-shared": minor
---

fix: remove extension name check when generating response

Current regex logic to check whether a pathname is a file (has file extension) is causing trouble for some websites, and now \${pathname}/index.html is always checked before returning notFound().
6 changes: 0 additions & 6 deletions packages/pages-shared/asset-server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ export async function generateHandler<
);
} else if ((assetEntry = await findAssetEntryForPath(`${pathname}.html`))) {
return serveAsset(assetEntry);
} else if (hasFileExtension(pathname)) {
return notFound();
}

if ((assetEntry = await findAssetEntryForPath(`${pathname}/index.html`))) {
Expand Down Expand Up @@ -626,10 +624,6 @@ function isCacheable(request: Request) {
return !request.headers.has("authorization") && !request.headers.has("range");
}

function hasFileExtension(path: string) {
return /\/.+\.[a-z0-9]+$/i.test(path);
}

// Parses a request URL hostname to determine if the request
// is from a project served in "preview" mode.
function isPreview(url: URL): boolean {
Expand Down

0 comments on commit 41294df

Please sign in to comment.