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

server: listen to port 80 && extract subdomain from req

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