Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/passport-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
const socket = io("ws://localhost:3000", {
// set this option to send cookies for session-management to work
withCredentials: true
});
const socketIdSpan = document.getElementById("socketId");
const usernameSpan = document.getElementById("username");

Expand Down
14 changes: 13 additions & 1 deletion examples/passport-example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@ passport.deserializeUser((id, cb) => {
cb(null, DUMMY_USER);
});

const io = require('socket.io')(server);
const io = require('socket.io').Server(server, {
/**
* We don't strictly need CORS configuration for this example because the socket.io server and the client are
* on the same host:port, but this is a sample configuration when you do need it.
* See "Handling CORS" in documentation for full documentation of options.
**/
cors: {
origin: [`http://localhost:${port}`],
methods: ['GET', 'POST'],
// include this to accept cookies, used by express-session for the session-identifying cookie
credentials: true
},
});

// convert a connect middleware to a Socket.IO middleware
const wrap = middleware => (socket, next) => middleware(socket.request, {}, next);
Expand Down