From 14c33b7fc644e00023c324069deac4c5b4d3fe02 Mon Sep 17 00:00:00 2001 From: Ashley Lewis Date: Thu, 26 Sep 2019 17:06:58 -0500 Subject: [PATCH] use one liner for not found request mapper --- workers-site/index.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/workers-site/index.js b/workers-site/index.js index e4ffad8..ac0ea9c 100644 --- a/workers-site/index.js +++ b/workers-site/index.js @@ -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 }) @@ -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