TLENS
TLENS
CDCloudflare Developers
Created by TLENS on 9/27/2024 in #workers-help
How configure workers with assets for intercept public/index.html
i have wrangler.toml:
name = "my-worker-assets"
main = "src/index.ts"
compatibility_date = "2024-09-25"
compatibility_flags = ["nodejs_compat"]
assets = { directory = "./public", binding = "ASSETS" }
name = "my-worker-assets"
main = "src/index.ts"
compatibility_date = "2024-09-25"
compatibility_flags = ["nodejs_compat"]
assets = { directory = "./public", binding = "ASSETS" }
I need to add middleware to request.url == "/" but static files don't get into the default handler
export default {
async fetch(request, env, ctx): Promise<Response> {
const url = new URL(request.url);
console.log(url);
switch (url.pathname) {
case '/message':
return new Response('Hello, World!');
case '/random':
return new Response(crypto.randomUUID());
default:
return new Response('Not Found', { status: 404 });
}
},
} satisfies ExportedHandler<Env>;
export default {
async fetch(request, env, ctx): Promise<Response> {
const url = new URL(request.url);
console.log(url);
switch (url.pathname) {
case '/message':
return new Response('Hello, World!');
case '/random':
return new Response(crypto.randomUUID());
default:
return new Response('Not Found', { status: 404 });
}
},
} satisfies ExportedHandler<Env>;
4 replies