Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include cookie-related CORS config in passport-example #3864

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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