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

Create basic web server framework

- uses HOSTNAME env var for root domain, falling back to locahost
- uses PORT env var for port, falling back to 8000 (as non privileged)
- extracts subdomain from url and WILL match it, but not currently
- Returns "404 could not resolve domain" if not matched

vielle.dev 20dcf200

Changed files
+23
+6
deno.json
··· 1 + { 2 + "tasks": { 3 + "dev": "deno run --watch --allow-net --allow-env=HOSTNAME,PORT main.ts" 4 + }, 5 + "imports": {} 6 + }
+17
main.ts
··· 1 + const ROOT_DOMAIN = Deno.env.get("HOSTNAME") || "localhost"; 2 + const SUBDOMAIN_REGEX = new RegExp(`.+(?=\\.${ROOT_DOMAIN}$)`, "gm"); 3 + 4 + Deno.serve( 5 + { port: parseInt("" + Deno.env.get("PORT")) || 8000, hostname: ROOT_DOMAIN }, 6 + (req) => { 7 + const reqUrl = new URL(req.url); 8 + const subdomain = reqUrl.hostname.match(SUBDOMAIN_REGEX)?.at(0); 9 + 10 + return new Response( 11 + `Could not resolve domain "${subdomain ?? ""}${subdomain ? "." : ""}${ROOT_DOMAIN}"`, 12 + { 13 + status: 404, 14 + } 15 + ); 16 + } 17 + );