forked from
nekomimi.pet/wisp.place-monorepo
Monorepo for Wisp.place. A static site hosting service built on top of the AT Protocol.
1import { Elysia } from 'elysia'
2import { cors } from '@elysiajs/cors'
3import { staticPlugin } from '@elysiajs/static'
4import { openapi, fromTypes } from '@elysiajs/openapi'
5
6import type { Config } from './lib/types'
7import { BASE_HOST } from './lib/constants'
8import {
9 createClientMetadata,
10 getOAuthClient,
11 getCurrentKeys
12} from './lib/oauth-client'
13import { authRoutes } from './routes/auth'
14import { wispRoutes } from './routes/wisp'
15import { domainRoutes } from './routes/domain'
16
17const config: Config = {
18 domain: (Bun.env.DOMAIN ?? `https://${BASE_HOST}`) as `https://${string}`,
19 clientName: Bun.env.CLIENT_NAME ?? 'PDS-View'
20}
21
22const client = await getOAuthClient(config)
23
24export const app = new Elysia()
25 .use(
26 openapi({
27 references: fromTypes()
28 })
29 )
30 .use(
31 await staticPlugin({
32 prefix: '/'
33 })
34 )
35 .use(authRoutes(client))
36 .use(wispRoutes(client))
37 .use(domainRoutes(client))
38 .get('/client-metadata.json', (c) => {
39 return createClientMetadata(config)
40 })
41 .get('/jwks.json', (c) => {
42 const keys = getCurrentKeys()
43 if (!keys.length) return { keys: [] }
44
45 return {
46 keys: keys.map((k) => {
47 const jwk = k.publicJwk ?? k
48 const { ...pub } = jwk
49 return pub
50 })
51 }
52 })
53 .use(cors())
54 .listen(8000)
55
56console.log(
57 `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
58)