mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
20 lines
619 B
TypeScript
20 lines
619 B
TypeScript
/**
|
|
* ChatLab API — Fastify server instance
|
|
*/
|
|
|
|
import type { FastifyInstance } from 'fastify'
|
|
import { createBearerAuthHook } from '@openchatlab/http-routes/auth'
|
|
import { createApiServer } from '@openchatlab/http-routes/server'
|
|
import { getConfig } from './index'
|
|
import { apiLogger } from './logger'
|
|
|
|
export function createServer(): FastifyInstance {
|
|
return createApiServer({
|
|
authHook: createBearerAuthHook({
|
|
getToken: () => getConfig().token,
|
|
allowMissingToken: false,
|
|
}),
|
|
onUnhandledError: (request, error) => apiLogger.error(`${request.method} ${request.url} -> 500`, error),
|
|
})
|
|
}
|