mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-08 11:21:40 +02:00
testing new socket.io-client extraHeaders (#5985)
* testing new socket.io-client extraHeaders * change mongodb installation
This commit is contained in:
committed by
GitHub
parent
1c5bdcb670
commit
557dfd5b47
@@ -5,7 +5,6 @@ var nconf = require('nconf');
|
||||
var fs = require('fs');
|
||||
var winston = require('winston');
|
||||
|
||||
var myXhr = require('../mocks/newXhr');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
var helpers = module.exports;
|
||||
@@ -66,28 +65,22 @@ helpers.logoutUser = function (jar, callback) {
|
||||
};
|
||||
|
||||
helpers.connectSocketIO = function (res, callback) {
|
||||
myXhr.callbacks.headerCallback = function () {
|
||||
this.setDisableHeaderCheck(true);
|
||||
var stdOpen = this.open;
|
||||
this.open = function () {
|
||||
stdOpen.apply(this, arguments);
|
||||
this.setRequestHeader('Cookie', res.headers['set-cookie'][0].split(';')[0]);
|
||||
this.setRequestHeader('Origin', nconf.get('url'));
|
||||
};
|
||||
};
|
||||
var io = require('socket.io-client');
|
||||
|
||||
var socketClient = require('socket.io-client');
|
||||
|
||||
var io = socketClient.connect(nconf.get('base_url'), {
|
||||
var cookie = res.headers['set-cookie'][0].split(';')[0];
|
||||
var socket = io(nconf.get('base_url'), {
|
||||
path: nconf.get('relative_path') + '/socket.io',
|
||||
forceNew: true,
|
||||
multiplex: false,
|
||||
});
|
||||
io.on('connect', function () {
|
||||
callback(null, io);
|
||||
extraHeaders: {
|
||||
Origin: nconf.get('url'),
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
|
||||
io.on('error', function (err) {
|
||||
socket.on('connect', function () {
|
||||
callback(null, socket);
|
||||
});
|
||||
|
||||
socket.on('error', function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// see https://gist.github.com/jfromaniello/4087861#gistcomment-1447029
|
||||
// XMLHttpRequest to override.
|
||||
|
||||
var npm2Path = '../../node_modules/socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl';
|
||||
var npm3Path = '../../node_modules/xmlhttprequest-ssl';
|
||||
var filePath;
|
||||
var winston = require('winston');
|
||||
|
||||
// Make initial call to require so module is cached.
|
||||
try {
|
||||
require(npm2Path);
|
||||
filePath = require.resolve(npm2Path);
|
||||
} catch (err) {
|
||||
if (err) {
|
||||
winston.info('Couldn\'t find ' + npm2Path);
|
||||
}
|
||||
try {
|
||||
require(npm3Path);
|
||||
filePath = require.resolve(npm3Path);
|
||||
} catch (err) {
|
||||
if (err) {
|
||||
winston.info('Couldn\'t find ' + npm3Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
winston.info('xmlhttprequest-ssl path: ' + filePath);
|
||||
// Get cached version.
|
||||
var cachedXhr = require.cache[filePath];
|
||||
var stdXhr = cachedXhr.exports;
|
||||
|
||||
// Callbacks exposes an object that callback functions can be added to.
|
||||
var callbacks = {};
|
||||
|
||||
var newXhr = function () {
|
||||
stdXhr.apply(this, arguments);
|
||||
for (var method in callbacks) {
|
||||
if (typeof callbacks[method] === 'function') {
|
||||
callbacks[method].apply(this, arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
newXhr.XMLHttpRequest = newXhr;
|
||||
|
||||
cachedXhr.exports = newXhr;
|
||||
module.exports = newXhr;
|
||||
module.exports.callbacks = callbacks;
|
||||
Reference in New Issue
Block a user