let options = {
mapRequestToAsset: (request) => {
// First apply the default handler, which already has logic to detect
// paths that should map to HTML files.
request = mapRequestToAsset(request)
const parsedUrl = new URL(request.url)
// Detect if the default handler decided to map to
// a HTML file in some specific directory.
if (parsedUrl.pathname.endsWith('.html')) {
// If expected HTML file was missing, just return the root index.html
return new Request(`${parsedUrl.origin}/200.html`, request)
} else {
// The default handler decided this is not an HTML page. It's probably
// an image, CSS, or JS file. Leave it as-is.
return request
}
}
}
return await getAssetFromKV(event, options)
But since I'm copying the function just to change one line, what I want to do is something like:
let options = {
mapRequestToAsset: serveSinglePageApp,
fallback: '200.html'
}
return await getAssetFromKV(event, options)
I'm personally not sure the best way to achieve this, but I think adding it to options and then passing it to the const requestKey = ASSET_MANIFEST[rawPathKey] ? request : options.mapRequestToAsset(request)
line would work.