2023-02-02 15:47:05 +00:00
|
|
|
import { cors } from 'wildebeest/backend/src/utils/cors'
|
2023-02-22 16:09:43 +00:00
|
|
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
2023-02-02 15:47:05 +00:00
|
|
|
import type { Env } from 'wildebeest/backend/src/types/env'
|
|
|
|
import { getPeers } from 'wildebeest/backend/src/activitypub/peers'
|
|
|
|
|
|
|
|
export const onRequest: PagesFunction<Env, any> = async ({ env }) => {
|
2023-02-27 17:37:03 +00:00
|
|
|
return handleRequest(await getDatabase(env))
|
2023-02-02 15:47:05 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 16:09:43 +00:00
|
|
|
export async function handleRequest(db: Database): Promise<Response> {
|
2023-02-02 15:47:05 +00:00
|
|
|
const headers = {
|
|
|
|
...cors(),
|
|
|
|
'content-type': 'application/json; charset=utf-8',
|
|
|
|
}
|
|
|
|
const peers = await getPeers(db)
|
|
|
|
return new Response(JSON.stringify(peers), { headers })
|
|
|
|
}
|