+6
deno.json
+6
deno.json
+17
main.ts
+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
+
);