How to serve static assets and turn "Hello World Worker" c3 template into a Pages project?

Hi I just created a new project using c3 and no framework. I chose the option of "Hello World worker" in the c2 wizard. I want to host this on Pages and use some static assets. I am not sure how to do either. For static assets, I have created a root level folder called "pub" and added my static assets there. In wrangler.toml, i have;
name = "silver"
main = "src/server.js"
compatibility_date = "2023-06-28"

[site]
bucket = "./pub" # Add the directory with your static assets!
name = "silver"
main = "src/server.js"
compatibility_date = "2023-06-28"

[site]
bucket = "./pub" # Add the directory with your static assets!
Finally, my worker script is in the src/server.js file
import { showAboutPage } from "./handlers/showAboutPage";


export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
if (url.pathname.startsWith("/pub")) {
return env.ASSETS.fetch(request);
}
return new Response(await showAboutPage());
},
};
import { showAboutPage } from "./handlers/showAboutPage";


export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
if (url.pathname.startsWith("/pub")) {
return env.ASSETS.fetch(request);
}
return new Response(await showAboutPage());
},
};
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server