Created
December 21, 2015 08:46
-
-
Save naholyr/289956773ec96458a56a to your computer and use it in GitHub Desktop.
Express + socket.io CLI client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'); | |
var request = require('request-promise'); | |
var io = require('socket.io-client'); | |
var jar = request.jar(); | |
/** | |
* Connect to web interface | |
*/ | |
request({ | |
uri: loginActionUrl, | |
form: { login, password }, | |
jar | |
}) | |
.then(function () { | |
return io(server, { | |
// Pass cookies manually as http requests are not shared | |
query: 'cookie=' + escape(jar.getCookieString(root)) | |
}) | |
}) | |
.then(function (socket) { | |
return model.on('connect', function () { | |
console.log('OK') | |
process.exit(0) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socketio = require('socket.io') | |
var io = socketio(server) | |
io.use((socket, next) => { | |
if (socket.handshake.query.cookie) { | |
// Set Cookie from query string in case headers are not available | |
socket.handshake.headers.cookie = socket.handshake.query.cookie; | |
} | |
next() | |
}) | |
io.use(checkExpressSession) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment