[WIP] A (somewhat barebones) atproto app for creating custom sites without hosting!
at main 38 lines 911 B view raw
1import { ROOT_DOMAIN } from "../utils.ts"; 2import index from "../www/index.html" with { type: "text" }; 3import ascii from "./ascii.txt" with { type: "text" }; 4 5function route( 6 path: string, 7 callback: (req: Request) => Response 8): { 9 test: (path: string) => boolean; 10 fn: (req: Request) => Response; 11} { 12 const pattern = new URLPattern(path, `https://www.${ROOT_DOMAIN}`); 13 return { 14 test: (path) => pattern.test(path, `https://www.${ROOT_DOMAIN}`), 15 fn: callback, 16 }; 17} 18 19const routes = [ 20 route( 21 "/", 22 () => 23 new Response(index, { 24 headers: { 25 "Content-Type": "text/html; charset=utf8", 26 }, 27 }) 28 ), 29 route("/ascii.txt", () => new Response(ascii)), 30]; 31 32export default function (req: Request) { 33 const path = new URL(req.url).pathname; 34 for (const r of routes) if (r.test(path)) return r.fn(req); 35 return new Response("404", { 36 status: 404, 37 }); 38}