|
1 | | -import Fastify, { FastifyBaseLogger } from "fastify"; |
| 1 | +import Fastify from "fastify"; |
2 | 2 | import helmet from "@fastify/helmet"; |
3 | 3 | import cors from "@fastify/cors"; |
4 | 4 | import sensible from "@fastify/sensible"; |
5 | | -import { createPinoLogger } from "@uma/logger"; |
| 5 | +import { createPinoConfig } from "@uma/logger"; |
6 | 6 | import { loadEnv } from "./env.js"; |
7 | 7 | import { createQueue } from "./queue.js"; |
8 | 8 | import { TicketQueueService } from "./services/TicketService.js"; |
9 | 9 | import { ticketsRoutes } from "./routes/tickets.js"; |
10 | 10 |
|
11 | 11 | export async function buildServer(): Promise<{ app: ReturnType<typeof Fastify>; start: () => Promise<void> }> { |
12 | 12 | const env = loadEnv(); |
13 | | - const logger = createPinoLogger({ |
14 | | - level: process.env.LOG_LEVEL || "info", |
15 | | - botIdentifier: process.env.BOT_IDENTIFIER || "ticketing-api", |
16 | | - }) as FastifyBaseLogger; |
17 | | - const app = Fastify({ loggerInstance: logger }); |
| 13 | + const app = Fastify({ |
| 14 | + logger: createPinoConfig({ |
| 15 | + level: process.env.LOG_LEVEL || "info", |
| 16 | + botIdentifier: process.env.BOT_IDENTIFIER || "ticketing-api", |
| 17 | + }), |
| 18 | + }); |
18 | 19 |
|
19 | 20 | await app.register(helmet); |
20 | 21 | await app.register(cors, { origin: true, credentials: true }); |
21 | 22 | await app.register(sensible); |
22 | 23 |
|
23 | | - const queue = createQueue(env, app.log); |
24 | | - const ticketService = new TicketQueueService(queue, env); |
| 24 | + const ticketQueue = createQueue(env, app.log); |
| 25 | + const ticketService = new TicketQueueService(ticketQueue.queue, env); |
25 | 26 | await ticketsRoutes(app, ticketService); |
26 | 27 |
|
| 28 | + app.addHook("onClose", async () => { |
| 29 | + await ticketQueue.close(); |
| 30 | + }); |
| 31 | + |
27 | 32 | app.get("/health", async (_, reply) => { |
28 | 33 | return reply.status(200).send({ ok: true }); |
29 | 34 | }); |
|
0 commit comments