2023-09-16 00:28:06 +00:00
|
|
|
import { ACCOUNT, ACTOR, HOSTNAME, PORT } from "./env";
|
|
|
|
|
import admin from './admin'
|
|
|
|
|
import activitypub from "./activitypub";
|
2023-09-20 06:43:48 +00:00
|
|
|
import { fetchObject } from "./request";
|
2023-09-16 00:28:06 +00:00
|
|
|
|
|
|
|
|
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" }})
|
|
|
|
|
}
|
2023-09-20 06:43:48 +00:00
|
|
|
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)
|
|
|
|
|
}
|
2023-09-16 00:28:06 +00:00
|
|
|
|
|
|
|
|
return admin(req) || activitypub(req) || new Response("How did we get here?", { status: 404 })
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log(`Listening on http://localhost:${server.port} ...`);
|