I have a scenario where my match-all route attempts to serve that static asset from the build
dir. In the event that the asset can’t be found, I would like to serve a default asset. Take the following paths for example:
/manifest.json
→ /build/manifest.json
/robots.txt
→ /build/robots.txt
/about
→ /build/about
doesn’t exist, so onNotFound
should serve /build/index.html
/users
→ /build/about
doesn’t exist, so onNotFound
should serve /build/index.html
The last 2 routes are client-side and instead of individually defining them to serve index.html
, I’d like it to just default to a specific asset.
.match('/:path*', ({ serveStatic, request }) => {
console.log(`attempting to serve ${request.path}`);
serveStatic('build/:path*', {
onNotFound: () => {
console.log('serving default index.html');
serveStatic('build/index.html');
},
});
})
In this handler, the first log is always called, but never reaches the second if the asset can’t be found. The response is just a 404. Is this intended?