import { ACCOUNT, ACTOR, HOSTNAME, PORT } from "./env"; import admin from './admin' import activitypub from "./activitypub"; import { fetchObject } from "./request"; const server = Bun.serve({ port: 3000, fetch(req): Response | Promise { const url = new URL(req.url) console.log(`${new Date().toISOString()} ${req.method} ${req.url}`) if(req.method === "GET" && url.pathname === "/.well-known/webfinger") { const resource = url.searchParams.get("resource") if(resource !== `acct:${ACCOUNT}@${HOSTNAME}`) return new Response("", { status: 404 }) return Response.json({ subject: `acct:${ACCOUNT}@${HOSTNAME}`, links: [ { rel: "self", type: "application/activity+json", href: ACTOR, }, ], }, { headers: { "content-type": "application/activity+json" }}) } else if(req.method === "GET" && url.pathname === "/fetch") { const object_url = url.searchParams.get('url') if(!object_url) return new Response("No url supplied", { status: 400}) return fetchObject(ACTOR, object_url) } return admin(req) || activitypub(req) || new Response("How did we get here?", { status: 404 }) }, }); console.log(`Listening on http://localhost:${server.port} ...`);