adding assets to workers is sick and i'

adding assets to workers is sick and i've got it working. but not_found_handling = "single-page-application" doesn't seem to quite work without handling in the worker? Am i right about that? You want to bind it and hand the request back to assets to get the correct asset.
3 Replies
stridex
stridexOP3mo ago
// Point all other requests to the assets
app.get('*', async ctx => {
const response = await ctx.env.ASSETS.fetch(ctx.req.raw);
// clone the response to return a response with modifiable headers
const newResponse = new Response(response.body, response);
return newResponse;
});
// Point all other requests to the assets
app.get('*', async ctx => {
const response = await ctx.env.ASSETS.fetch(ctx.req.raw);
// clone the response to return a response with modifiable headers
const newResponse = new Response(response.body, response);
return newResponse;
});
Wonky Onion
Wonky Onion3mo ago
yup, you have to use the ASSETS binding to access not_found_handling behaviour from your worker (exactly like you've done) - there's a snippet here in the docs that shows it: https://developers.cloudflare.com/workers/static-assets/binding/#runtime-api-reference We should probably add it to the not_found_handling section too...
Cloudflare Docs
Configuration and binding | Cloudflare Workers docs
Details on how to configure Workers static assets and its binding.
Wonky Onion
Wonky Onion3mo ago
glad you're liking workers assets though :D
Want results from more Discord servers?
Add your server