mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Websocket loadbalancers might run in tcp mode, which makes it difficult to add the X-Forwarded-For header. Pass the IP in the query string instead.
This commit is contained in:
parent
7cb8fff6ac
commit
1932c17508
3 changed files with 21 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
||||||
var http = require('http')
|
var http = require('http')
|
||||||
|
var url = require('url')
|
||||||
|
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var validator = require('express-validator')
|
var validator = require('express-validator')
|
||||||
|
@ -116,28 +117,19 @@ module.exports = function(options) {
|
||||||
res.render('index')
|
res.render('index')
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/api/v1/appstate.js', function(req, res) {
|
app.get('/api/v1/app/state.js', function(req, res) {
|
||||||
|
var state = {
|
||||||
|
config: {
|
||||||
|
websocketUrl: (function() {
|
||||||
|
var wsUrl = url.parse(options.websocketUrl, true)
|
||||||
|
wsUrl.query.uip = req.ip
|
||||||
|
return url.format(wsUrl)
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
, user: req.user
|
||||||
|
}
|
||||||
res.type('application/javascript')
|
res.type('application/javascript')
|
||||||
res.send('var GLOBAL_APPSTATE = ' + JSON.stringify({
|
res.send('var GLOBAL_APPSTATE = ' + JSON.stringify(state))
|
||||||
config: {
|
|
||||||
websocketUrl: options.websocketUrl
|
|
||||||
}
|
|
||||||
, user: req.user
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/api/v1/angular-appstate.js', function(req, res) {
|
|
||||||
res.type('application/javascript')
|
|
||||||
res.send('angular.module("stf.app-state")' +
|
|
||||||
'.config(function(AppState){AppState.set(' +
|
|
||||||
JSON.stringify({
|
|
||||||
config: {
|
|
||||||
websocketUrl: options.websocketUrl
|
|
||||||
}
|
|
||||||
, user: req.user
|
|
||||||
}) +
|
|
||||||
')})')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/api/v1/app/user', function(req, res) {
|
app.get('/api/v1/app/user', function(req, res) {
|
||||||
|
|
|
@ -66,10 +66,12 @@ module.exports = function(options) {
|
||||||
io.use(auth)
|
io.use(auth)
|
||||||
|
|
||||||
io.on('connection', function(socket) {
|
io.on('connection', function(socket) {
|
||||||
var channels = []
|
var req = socket.request
|
||||||
, user = socket.request.user
|
, user = req.user
|
||||||
|
, channels = []
|
||||||
|
|
||||||
socket.emit('socket.ip', socket.request.ip)
|
user.ip = socket.handshake.query.uip || req.ip
|
||||||
|
socket.emit('socket.ip', user.ip)
|
||||||
|
|
||||||
function joinChannel(channel) {
|
function joinChannel(channel) {
|
||||||
channels.push(channel)
|
channels.push(channel)
|
||||||
|
@ -672,7 +674,7 @@ module.exports = function(options) {
|
||||||
.on('forward.test', function(channel, responseChannel, data) {
|
.on('forward.test', function(channel, responseChannel, data) {
|
||||||
joinChannel(responseChannel)
|
joinChannel(responseChannel)
|
||||||
if (!data.targetHost || data.targetHost === 'localhost') {
|
if (!data.targetHost || data.targetHost === 'localhost') {
|
||||||
data.targetHost = socket.request.ip
|
data.targetHost = user.ip
|
||||||
}
|
}
|
||||||
push.send([
|
push.send([
|
||||||
channel
|
channel
|
||||||
|
@ -684,7 +686,7 @@ module.exports = function(options) {
|
||||||
})
|
})
|
||||||
.on('forward.create', function(channel, responseChannel, data) {
|
.on('forward.create', function(channel, responseChannel, data) {
|
||||||
if (!data.targetHost || data.targetHost === 'localhost') {
|
if (!data.targetHost || data.targetHost === 'localhost') {
|
||||||
data.targetHost = socket.request.ip
|
data.targetHost = user.ip
|
||||||
}
|
}
|
||||||
joinChannel(responseChannel)
|
joinChannel(responseChannel)
|
||||||
push.send([
|
push.send([
|
||||||
|
|
|
@ -26,7 +26,7 @@ html(ng-app='app')
|
||||||
div(growl)
|
div(growl)
|
||||||
div(ng-view).fill-height
|
div(ng-view).fill-height
|
||||||
|
|
||||||
script(src='/api/v1/appstate.js')
|
script(src='/api/v1/app/state.js')
|
||||||
script(src='static/app/build/entry/commons.entry.js')
|
script(src='static/app/build/entry/commons.entry.js')
|
||||||
script(src='static/app/build/entry/app.entry.js')
|
script(src='static/app/build/entry/app.entry.js')
|
||||||
script(src='static/bower_components/stf-analytics/analytics.js')
|
script(src='static/bower_components/stf-analytics/analytics.js')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue