Skip to content

Commit

Permalink
Give a more sensible error message for unhandled routes.
Browse files Browse the repository at this point in the history
Also redirect any request URLs consisting of double slashes.
  • Loading branch information
LTLA committed Apr 23, 2024
1 parent 447de79 commit 5b7c187
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ router.get("/", () => {
return new Response(null, { headers: { "Location": "https://artifactdb.github.io/gypsum-worker" }, status: 301 })
})

router.all('*', request => {
const u = request.url;
const pattern = /([^:])(\/\/+)/g;
if (u.match(pattern)) {
return new Response(null, { headers: { "Location": u.replace(pattern, "$1/") }, status: 301 })
}
return http.errorResponse("no such endpoint", 404);
})

export default {

fetch(request, env, context) {
Expand Down

0 comments on commit 5b7c187

Please sign in to comment.