Skip to content

Commit de150ed

Browse files
committed
WIP implements shutdown to main
1 parent 4a6f85f commit de150ed

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

service/src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import { join } from 'path'
77
import { AppModule } from './app.module'
88
import * as cookieParser from 'cookie-parser'
99
import * as passport from 'passport'
10+
import { ShutdownService } from '~/shutdown.service'
11+
import * as process from 'process'
1012

1113
declare const module: any
1214
;(async (): Promise<void> => {
1315
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
1416
cors: true,
1517
})
16-
app.use((_, res: Response, next: () => void) => {
18+
app.get(ShutdownService).subscribeToShutdown(async () => {
19+
await app.close()
20+
process.exit(0)
21+
})
22+
app.use((_: any, res: Response, next: () => void) => {
1723
res.removeHeader('x-powered-by')
1824
next()
1925
})

0 commit comments

Comments
 (0)