1
0

fix: robust web/dist path resolution and graceful shutdown

This commit is contained in:
2026-08-29 17:59:22 +02:00
parent a3bf420282
commit 061f7349b5
2 changed files with 13 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import cookie from '@fastify/cookie'
import fastifyStatic from '@fastify/static' import fastifyStatic from '@fastify/static'
import path from 'node:path' import path from 'node:path'
import { existsSync } from 'node:fs' import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import type { Config } from './config.js' import type { Config } from './config.js'
import { SerialQueue } from './queue.js' import { SerialQueue } from './queue.js'
import { SyncManager } from './sync.js' import { SyncManager } from './sync.js'
@@ -56,7 +57,8 @@ export async function buildApp(opts: AppOptions): Promise<FastifyInstance> {
decorateReply: false, decorateReply: false,
}) })
const webDist = opts.webDist ?? path.resolve('web/dist') const moduleDir = path.dirname(fileURLToPath(import.meta.url))
const webDist = opts.webDist ?? path.resolve(moduleDir, '../../web/dist')
const hasWeb = existsSync(webDist) const hasWeb = existsSync(webDist)
if (hasWeb) { if (hasWeb) {
await app.register(fastifyStatic, { root: webDist, prefix: '/' }) await app.register(fastifyStatic, { root: webDist, prefix: '/' })

View File

@@ -6,3 +6,13 @@ const config = loadConfig()
const db = openDatabase(config.dbPath) const db = openDatabase(config.dbPath)
const app = await buildApp({ db, config }) const app = await buildApp({ db, config })
await app.listen({ port: config.port, host: '0.0.0.0' }) await app.listen({ port: config.port, host: '0.0.0.0' })
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
process.on(signal, () => {
void (async () => {
await app.close()
db.close()
process.exit(0)
})()
})
}