step 2, updated readme

This commit is contained in:
Screeny 2013-11-19 10:52:36 +01:00
parent f31dc4a93e
commit 1a3b3e1cdc

View File

@ -121,9 +121,27 @@ passportSocketIo.filterSocketsByUser(io, function(user){
}); });
``` ```
## CORS-Workaround:
If you happen to have to work with Cross-Origin-Requests (marked by socket.io as `handshake.xdomain`) then here's a workaround:
### Clientside:
You have to provide the session-cookie. If you haven't set a name yet, do it like this: `app.use(express.session({ key: 'your.sid-key' }));`
```javascript
// Note: ther's no readCookie-function built in.
// Get your own in the internetz
socket = io.connect('//' + window.location.host, {
query: 'session_id=' + readCookie('your.sid-key')
});
```
### Serverside:
Nope, there's nothing to do on the server side. Just be sure that the cookies names match.
## Notes: ## Notes:
* Does **NOT** support cookie-based sessions. eg: `express.cookieSession` * Does **NOT** support cookie-based sessions. eg: `express.cookieSession`
* If the connection fails, check if you are requesting from a client via CORS. Check `socket.handshake.xdomain === true` as there are no cookies sent. * If the connection fails, check if you are requesting from a client via CORS. Check `socket.handshake.xdomain === true` as there are no cookies sent. For a workaround look at the code above.
## Contribute ## Contribute
You are always welcome to open an issue or provide a pull-request! You are always welcome to open an issue or provide a pull-request!