tangled
alpha
login
or
join now
vielle.dev
/
atcities.dev
8
fork
atom
[WIP] A (somewhat barebones) atproto app for creating custom sites without hosting!
8
fork
atom
overview
issues
pulls
pipelines
server: listen to port 80 && extract subdomain from req
vielle.dev
5 months ago
c97f2b7f
20dcf200
+13
-14
2 changed files
expand all
collapse all
unified
split
deno.json
main.ts
+1
-1
deno.json
···
1
1
{
2
2
"tasks": {
3
3
-
"dev": "deno run --watch --allow-net --allow-env=HOSTNAME,PORT main.ts"
3
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
2
+
const PORT = Number(Deno.env.get("PORT")) || 80;
3
3
+
2
4
const SUBDOMAIN_REGEX = new RegExp(`.+(?=\\.${ROOT_DOMAIN}$)`, "gm");
3
5
4
4
-
Deno.serve(
5
5
-
{ port: parseInt("" + Deno.env.get("PORT")) || 8000, hostname: ROOT_DOMAIN },
6
6
-
(req) => {
7
7
-
const reqUrl = new URL(req.url);
8
8
-
const subdomain = reqUrl.hostname.match(SUBDOMAIN_REGEX)?.at(0);
6
6
+
Deno.serve({ port: PORT, hostname: ROOT_DOMAIN }, (req) => {
7
7
+
const reqUrl = new URL(req.url);
8
8
+
const subdomain = reqUrl.hostname.match(SUBDOMAIN_REGEX)?.at(0)?.split(".");
9
9
10
10
-
return new Response(
11
11
-
`Could not resolve domain "${subdomain ?? ""}${subdomain ? "." : ""}${ROOT_DOMAIN}"`,
12
12
-
{
13
13
-
status: 404,
14
14
-
}
15
15
-
);
16
16
-
}
17
17
-
);
10
10
+
return new Response(
11
11
+
`Could not resolve domain "${subdomain.join(".")}.${ROOT_DOMAIN}"`,
12
12
+
{
13
13
+
status: 404,
14
14
+
}
15
15
+
);
16
16
+
});