From 1c75a580417653d6e6b53900ab3c6828cfc57be8 Mon Sep 17 00:00:00 2001 From: qaz741wsd856 Date: Sun, 25 Jan 2026 13:22:38 +0000 Subject: [PATCH] fix: add pathname normalization function to ensure consistent URL formatting --- src/entry.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/entry.js b/src/entry.js index 5ed8a36..46953f1 100644 --- a/src/entry.js +++ b/src/entry.js @@ -47,6 +47,13 @@ function normalizeUsername(username) { return v ? v : null; } +function normalizePathname(pathname) { + if (typeof pathname !== "string") return "/"; + // Keep "/" unchanged; otherwise remove one or more trailing slashes. + if (pathname === "/") return "/"; + return pathname.replace(/\/+$/, ""); +} + async function getHeavyDoShardKey(request, url) { const pathname = url.pathname; @@ -145,7 +152,10 @@ function parseDownloadPath(path) { // Main fetch handler export default { async fetch(request, env, ctx) { + // Normalize pathname to avoid trailing slashes const url = new URL(request.url); + url.pathname = normalizePathname(url.pathname); + request = new Request(url.toString(), request); const method = (request.method || "GET").toUpperCase(); // Optional: route selected CPU-heavy endpoints to Durable Objects.