From 9dd6b358faed280c559bedca3a069e1b751b911d Mon Sep 17 00:00:00 2001 From: Michael Mitchell Date: Tue, 17 Jan 2023 15:58:34 +1100 Subject: [PATCH] fix: trim trailing slash from path --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 85c0071..3e542b0 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,10 @@ async function handleRequest(event) { secret = WORKERLINKS_SECRET } - var key = new URL(request.url).pathname - var shorturl = new URL(request.url).origin + key + let path = new URL(request.url).pathname + // Trim trailing slash + let key = path !== '/' ? path.replace(/\/$/, '') : path; + let shorturl = new URL(request.url).origin + key if (request.method == 'PUT') { return await putLink(