Skip to content

Commit

Permalink
refactor: Remove socket.io/express compatibility layer
Browse files Browse the repository at this point in the history
socket.io now directly supports express middleware
  • Loading branch information
jrassa committed Jun 20, 2024
1 parent 3590c6a commit cdbf1a0
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/lib/socket.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import {
BaseSocketSubclass
} from '../app/common/sockets/base-socket.provider';

/**
* Adapt express middleware to work with Socket.IO
*/
function expressToIO(expressMiddleware) {
return (socket, next) =>
expressMiddleware(socket.request, socket.request.res, next);
}

class SocketIo {
/**
* Controllers created outside this class will register
Expand Down Expand Up @@ -80,22 +72,20 @@ class SocketIo {
});

// io.use(expressToIO(cookieParser(config.get('auth.sessionSecret'))));
io.use(
expressToIO(
expressSession({
saveUninitialized: true,
resave: true,
secret: config.get('auth.sessionSecret'),
cookie: config.get('auth.sessionCookie'),
store: MongoStore.create({
client: db.connection.getClient(),
collectionName: config.get('auth.sessionCollection')
} as unknown)
})
)
io.engine.use(
expressSession({
saveUninitialized: true,
resave: true,
secret: config.get('auth.sessionSecret'),
cookie: config.get('auth.sessionCookie'),
store: MongoStore.create({
client: db.connection.getClient(),
collectionName: config.get('auth.sessionCollection')
} as unknown)
})
);
io.use(expressToIO(passport.initialize()));
io.use(expressToIO(passport.session()));
io.engine.use(passport.initialize());
io.engine.use(passport.session());

// Verify if user was found in session
io.use((socket, next) => {
Expand Down

0 comments on commit cdbf1a0

Please sign in to comment.