project-knedita/src/server.ts

27 lines
635 B
TypeScript
Raw Normal View History

import app from './app'
import { createServer } from 'http'
import logger from 'helpers/logger'
import createSocketIOInstance from './socket'
2023-08-22 19:57:34 +00:00
import prisma from 'clients/prisma-client'
import redis from 'clients/redis-client'
const server = createServer(app)
const io = createSocketIOInstance(server)
app.use((req, res, next) => {
2023-09-02 19:11:41 +00:00
res.locals.io = io
next()
})
server.listen(process.env.SERVER_PORT, () => {
logger.info(`Server is running @ ${process.env.SERVER_PORT ?? ''}`)
})
2023-08-22 19:57:34 +00:00
process.on('SIGINT', async () => {
logger.warn('Closing server...')
await prisma.$disconnect()
await redis.disconnect()
server.close()
})