Merge pull request #7 from Ovyerus/fix/trailing-slash

fix: trim trailing slash from path
This commit is contained in:
Erisa A 2023-01-17 22:23:39 +00:00 committed by GitHub
commit cf1c7edc9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(