Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place
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' 16import { userRoutes } from './routes/user' 17 18const config: Config = { 19 domain: (Bun.env.DOMAIN ?? `https://${BASE_HOST}`) as `https://${string}`, 20 clientName: Bun.env.CLIENT_NAME ?? 'PDS-View' 21} 22 23const client = await getOAuthClient(config) 24 25export const app = new Elysia() 26 .use( 27 openapi({ 28 references: fromTypes() 29 }) 30 ) 31 .use( 32 await staticPlugin({ 33 prefix: '/' 34 }) 35 ) 36 .use(authRoutes(client)) 37 .use(wispRoutes(client)) 38 .use(domainRoutes(client)) 39 .use(userRoutes(client)) 40 .get('/client-metadata.json', (c) => { 41 return createClientMetadata(config) 42 }) 43 .get('/jwks.json', (c) => { 44 const keys = getCurrentKeys() 45 if (!keys.length) return { keys: [] } 46 47 return { 48 keys: keys.map((k) => { 49 const jwk = k.publicJwk ?? k 50 const { ...pub } = jwk 51 return pub 52 }) 53 } 54 }) 55 .use(cors({ 56 origin: config.domain, 57 credentials: true, 58 methods: ['GET', 'POST', 'DELETE', 'OPTIONS'], 59 allowedHeaders: ['Content-Type', 'Authorization'], 60 maxAge: 86400 // 24 hours 61 })) 62 .listen(8000) 63 64console.log( 65 `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}` 66)