Static site hosting via tangled
1import PagesService from "./pages-service.js"; 2 3let pagesService = null; 4 5// idk how long cloudflare will keep this around. 6// it would be better to save the config in a KV store 7// but this is good enough for now 8function getPagesService(env) { 9 if (!pagesService) { 10 pagesService = new PagesService({ 11 domain: env.KNOT_DOMAIN, 12 ownerDid: env.OWNER_DID, 13 repoName: env.REPO_NAME, 14 verbose: env.NODE_ENV === "development", 15 }); 16 } 17 return pagesService; 18} 19 20export default { 21 async fetch(request, env, ctx) { 22 const route = new URL(request.url).pathname; 23 const pagesService = getPagesService(env); 24 const { status, content, contentType } = await pagesService.getPage(route); 25 return new Response(content, { 26 status, 27 headers: { "Content-Type": contentType }, 28 }); 29 }, 30};