fix: add pathname normalization function to ensure consistent URL formatting
Some checks failed
Build / Run production build (push) Has been cancelled
Some checks failed
Build / Run production build (push) Has been cancelled
This commit is contained in:
parent
975f470ddf
commit
1c75a58041
1 changed files with 10 additions and 0 deletions
10
src/entry.js
10
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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue