33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
|
|
import { ACCOUNT, ACTOR, HOSTNAME, PORT } from "./env";
|
||
|
|
import admin from './admin'
|
||
|
|
import activitypub from "./activitypub";
|
||
|
|
|
||
|
|
const server = Bun.serve({
|
||
|
|
port: 3000,
|
||
|
|
fetch(req): Response | Promise<Response> {
|
||
|
|
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" }})
|
||
|
|
}
|
||
|
|
|
||
|
|
return admin(req) || activitypub(req) || new Response("How did we get here?", { status: 404 })
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log(`Listening on http://localhost:${server.port} ...`);
|