1+ import { Server } from 'socket.io' ;
2+ import http from 'http' ;
13import { App } from '@tinyhttp/app' ;
24import { cors } from '@tinyhttp/cors' ;
35import { jwt } from '@tinyhttp/jwt' ;
@@ -9,22 +11,24 @@ import { projectRoutes } from './project/project-routes';
911import { authRoutes } from './auth/auth-routes' ;
1012import { taskRoutes } from './task/task-routes' ;
1113
12-
1314const createApi = ( prisma : PrismaClient ) => {
1415 const app = new App ( ) ;
16+ const server = http . createServer ( ) ;
17+ server . on ( 'request' , app . attach ) ;
18+ const io = new Server ( server ) ;
1519
1620 app
1721 . use ( jwt ( { secret : process . env . JWT_SECRET ?? 'secret' , algorithm : 'HS256' } ) )
1822 . use ( cors ( ) )
1923 . use ( ( req , res , next ) => ( req . headers [ 'content-type' ] === 'application/json' ? json ( ) ( req , res , next ) : next ( ) ) )
2024 . use ( logger ( ) ) ;
2125
22- authRoutes ( app , prisma ) ;
23- userRoutes ( app , prisma ) ;
24- projectRoutes ( app , prisma ) ;
25- taskRoutes ( app , prisma ) ;
26+ authRoutes ( app , io , prisma ) ;
27+ userRoutes ( app , io , prisma ) ;
28+ projectRoutes ( app , io , prisma ) ;
29+ taskRoutes ( app , io , prisma ) ;
2630
27- return app ;
31+ return server ;
2832} ;
2933
3034export { createApi } ;
0 commit comments