Skip to content

Commit

Permalink
use one liner for not found request mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymichal committed Sep 26, 2019
1 parent 6bda846 commit 14c33b7
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions workers-site/index.js
Expand Up @@ -47,7 +47,7 @@ async function handleEvent(event) {
if (!DEBUG) {
try {
let notFoundResponse = await getAssetFromKV(event, {
mapRequestToAsset: notFoundAsset('404.html'),
mapRequestToAsset: req => new Request(`${new URL(req.url).origin}/404.html`, req),
})

return new Response(notFoundResponse.body, { ...notFoundResponse, status: 404 })
Expand All @@ -58,15 +58,6 @@ async function handleEvent(event) {
}
}

function notFoundAsset(assetName = '404.html') {
return request => {
const notFoundURL = new URL(request.url)
notFoundURL.pathname = assetName

return new Request(notFoundURL)
}
}

/**
* Here's one example of how to modify a request to
* remove a specific prefix, in this case `/docs` from
Expand Down

0 comments on commit 14c33b7

Please sign in to comment.