| 92 | const io = new Server(httpServer); |
| 93 | |
| 94 | function onlyForHandshake( |
| 95 | middleware: (req: Request, res: Response, next: any) => void, |
| 96 | ) { |
| 97 | return ( |
| 98 | req: Request & { _query: Record<string, string> }, |
| 99 | res: Response, |
| 100 | next: (err?: Error) => void, |
| 101 | ) => { |
| 102 | const isHandshake = req._query.sid === undefined; |
| 103 | if (isHandshake) { |
| 104 | middleware(req, res, next); |
| 105 | } else { |
| 106 | next(); |
| 107 | } |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | io.engine.use(onlyForHandshake(sessionMiddleware)); |
| 112 | io.engine.use(onlyForHandshake(passport.session())); |