summaryrefslogtreecommitdiff
path: root/src/pages/.well-known
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/.well-known')
-rw-r--r--src/pages/.well-known/onion.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/pages/.well-known/onion.ts b/src/pages/.well-known/onion.ts
new file mode 100644
index 0000000..552b5eb
--- /dev/null
+++ b/src/pages/.well-known/onion.ts
@@ -0,0 +1,20 @@
+import type { APIRoute } from "astro";
+import { env } from "../../lib/env.ts";
+
+const { PUBLIC_TOR_URL } = env;
+export const GET: APIRoute = (): Response => {
+ if (PUBLIC_TOR_URL === undefined) {
+ return new Response(null, { status: 404 });
+ }
+
+ let url: URL;
+ try {
+ url = new URL(PUBLIC_TOR_URL);
+ } catch {
+ return new Response("Invalid Tor URL", { status: 400 });
+ }
+
+ return new Response(url.host, {
+ headers: { "Onion-Location": url.href, "Content-Type": "text/plain" },
+ });
+};