mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-03 14:20:33 +01: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
@@ -1,10 +1,10 @@
|
||||
services:
|
||||
- redis-server
|
||||
before_install:
|
||||
- "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10"
|
||||
- "echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list"
|
||||
- "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6"
|
||||
- "echo 'deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list"
|
||||
- "sudo apt-get update"
|
||||
- "sudo apt-get install mongodb-org-server"
|
||||
- "sudo apt-get install -y mongodb-org"
|
||||
- "sudo service mongod start"
|
||||
before_script:
|
||||
- sleep 15 # wait for mongodb to be ready
|
||||
|
||||
@@ -109,9 +109,7 @@
|
||||
"istanbul": "^0.4.5",
|
||||
"jsdom": "^11.3.0",
|
||||
"mocha": "^3.5.3",
|
||||
"mocha-lcov-reporter": "^1.3.0",
|
||||
"xmlhttprequest": "1.8.0",
|
||||
"xmlhttprequest-ssl": "1.5.3"
|
||||
"mocha-lcov-reporter": "^1.3.0"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/NodeBB/NodeBB/issues"
|
||||
|
||||
@@ -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