1 file(s) changed
- api/src/createApp.ts +12 -0
api/src/createApp.ts
@@ -2,13 +2,16 @@ import express from 'express';
2 2 import cors from 'cors';
3 3 import bodyParser from 'body-parser';
4 4 import morgan from 'morgan';
5 + import mainRouter from '@app/routes/main';
5 6 import userRouter from '@app/routes/users';
6 7 import authRouter from '@app/routes/auth';
7 8 import { errorHandler } from '@app/middleware/errorHandler';
8 9 import { PrismaClient } from '@prisma/client';
10 + import { bootWorkers, closeAllWorkers, closeAllQueues } from '@app/lib/queue';
9 11
10 12 export function createApp() {
11 13 const app = express();
14 + bootWorkers();
12 15
13 16 // Configure CORS
14 17 app.use(cors({
@@ -23,10 +26,19 @@ if (process.env.NODE_ENV !== 'test') {
23 26 app.use(morgan('combined'));
24 27 }
25 28
29 + app.get('/', mainRouter);
26 30 app.use("/users", userRouter);
27 31 app.use("/auth", authRouter);
28 32
29 33 app.use(errorHandler); // always last
30 34
35 + process.on('SIGTERM', shutdown);
36 + process.on('SIGINT', shutdown);
37 +
31 38 return app;
32 39 }
40 +
41 + const shutdown = async () => {
42 + await Promise.all([closeAllWorkers(), closeAllQueues()]);
43 + process.exit(0);
44 + };