+1
-1
deno.json
+1
-1
deno.json
+12
-13
main.ts
+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
+
});