[WIP] A (somewhat barebones) atproto app for creating custom sites without hosting!

server: setup infra for index site and did/handle based subdomains

+34
+34
main.ts
··· 7 7 const reqUrl = new URL(req.url); 8 8 const subdomain = reqUrl.hostname.match(SUBDOMAIN_REGEX)?.at(0)?.split("."); 9 9 10 + // redirect ROOT_DOMAIN => www.ROOT_DOMAIN 11 + if (!subdomain) { 12 + const redirUrl = new URL(reqUrl.toString()); 13 + redirUrl.host = "www." + redirUrl.host; 14 + return new Response(`Redirecting to ${redirUrl.toString()}`, { 15 + status: 308, 16 + headers: { 17 + Location: redirUrl.toString(), 18 + }, 19 + }); 20 + } 21 + 22 + if (subdomain.length === 1 && subdomain[0] === "www") 23 + return new Response("Index site not implemented", { 24 + status: 501, 25 + }); 26 + 27 + // did:plc example: `sjkdgfjk.did-plc.ROOT_DOMAIN` 28 + // did:web example: `vielle.dev.did-web.ROOT_DOMAIN 29 + // last segment must start with `did-`, contain at least one letter/number, and cannot have any non alphanumeric characters after the hyphen 30 + if (subdomain.at(-1)?.match(/^did-[a-z0-9]+$/gm)) { 31 + return new Response("DID subdomains not implemented", { 32 + status: 501, 33 + }); 34 + } 35 + 36 + // ex: vielle.dev.ROOT_DOMAIN 37 + // cannot contain hyphen in top level domain 38 + if (subdomain.length > 1) { 39 + return new Response("Handle subdomains not implemented", { 40 + status: 501, 41 + }); 42 + } 43 + 10 44 return new Response( 11 45 `Could not resolve domain "${subdomain.join(".")}.${ROOT_DOMAIN}"`, 12 46 {