Skip to content

Commit

Permalink
Merge pull request #448 from sparcs-kaist/#447-refactor-start-socket-…
Browse files Browse the repository at this point in the history
…server-func

#447 startSocketServer 함수 리팩토링
  • Loading branch information
kmc7468 authored Feb 6, 2024
2 parents 4521d3d + 357f730 commit 98d8046
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions src/modules/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,13 @@ const emitUpdateEvent = async (io, roomId) => {
// https://socket.io/how-to/use-with-express-session 참고
const startSocketServer = (server) => {
const io = new Server(server, {
allowRequest: (req, callback) => {
const fakeRes = {
getHeader() {
return [];
},
setHeader(key, values) {
req.cookieHolder = values[0];
},
writeHead() {},
};
sessionMiddleware(req, fakeRes, () => {
if (req.session) {
fakeRes.writeHead();
req.session.save();
}
callback(null, true);
});
},
cors: {
origin: corsWhiteList,
methods: ["GET", "POST"],
credentials: true,
},
});

io.engine.on("initial_headers", (headers, req) => {
if (req.cookieHolder) {
headers["set-cookie"] = req.cookieHolder;
delete req.cookieHolder;
}
});
io.engine.use(sessionMiddleware);

io.on("connection", (socket) => {
try {
Expand Down

0 comments on commit 98d8046

Please sign in to comment.