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 4c18355
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ router.get("/", () => {
return new Response(null, { headers: { "Location": "https://artifactdb.github.io/gypsum-worker" }, status: 301 })
})

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

export default {

fetch(request, env, context) {
Expand Down

0 comments on commit 4c18355

Please sign in to comment.