Static site hosting via tangled
1import { Handler } from "./handler.js";
2import { Config } from "./config.js";
3import configObj from "../config.example.json"; // must be set at build time
4
5export default {
6 async fetch(request, env, ctx) {
7 const config = new Config(configObj);
8 const handler = await Handler.fromConfig(config);
9 const url = new URL(request.url);
10 const host = url.host;
11 const path = url.pathname;
12 const { status, content, contentType } = await handler.handleRequest({
13 host,
14 path,
15 });
16 return new Response(content, {
17 status,
18 headers: { "Content-Type": contentType },
19 });
20 },
21};