chore: scaffold node/ts/vitest project with health endpoint
This commit is contained in:
26
server/src/app.ts
Normal file
26
server/src/app.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import Fastify, { FastifyInstance } from 'fastify'
|
||||
import Database from 'better-sqlite3'
|
||||
import type { Config } from './config.js'
|
||||
|
||||
declare module 'fastify' {
|
||||
interface FastifyInstance {
|
||||
db: Database.Database
|
||||
config: Config
|
||||
fetchImpl: typeof fetch
|
||||
}
|
||||
}
|
||||
|
||||
export interface AppOptions {
|
||||
db: Database.Database
|
||||
config: Config
|
||||
fetchImpl?: typeof fetch
|
||||
}
|
||||
|
||||
export async function buildApp(opts: AppOptions): Promise<FastifyInstance> {
|
||||
const app = Fastify({ logger: false })
|
||||
app.decorate('db', opts.db)
|
||||
app.decorate('config', opts.config)
|
||||
app.decorate('fetchImpl', opts.fetchImpl ?? fetch)
|
||||
app.get('/api/health', async () => ({ ok: true }))
|
||||
return app
|
||||
}
|
||||
Reference in New Issue
Block a user