1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Add a poor reverse proxy for local development, the main difference being that everything except websockets now goes through the same port. Makes it easier to understand the production url layout.

This commit is contained in:
Simo Kinnunen 2014-10-23 13:28:18 +09:00
parent cd1f9108ce
commit 6d88a28a2c
3 changed files with 140 additions and 54 deletions

62
lib/units/poorxy/index.js Normal file
View file

@ -0,0 +1,62 @@
var http = require('http')
var express = require('express')
var httpProxy = require('http-proxy')
var logger = require('../../util/logger')
module.exports = function(options) {
var log = logger.createLogger('poorxy')
, app = express()
, server = http.createServer(app)
, proxy = httpProxy.createProxyServer()
proxy.on('error', function(err) {
log.error('Proxy had an error', err.stack)
})
app.set('strict routing', true)
app.set('case sensitive routing', true)
app.set('trust proxy', true)
;['/api/v1/auth/*', '/static/auth/*', '/auth/*'].forEach(function(route) {
app.all(route, function(req, res) {
proxy.web(req, res, {
target: options.authUrl
})
})
})
;['/api/v1/s/image/*'].forEach(function(route) {
app.all(route, function(req, res) {
proxy.web(req, res, {
target: options.storagePluginImageUrl
})
})
})
;['/api/v1/s/apk/*'].forEach(function(route) {
app.all(route, function(req, res) {
proxy.web(req, res, {
target: options.storagePluginApkUrl
})
})
})
;['/api/v1/s*'].forEach(function(route) {
app.all(route, function(req, res) {
proxy.web(req, res, {
target: options.storageUrl
})
})
})
app.use(function(req, res) {
proxy.web(req, res, {
target: options.appUrl
})
})
server.listen(options.port)
log.info('Listening on port %d', options.port)
}