mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +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:
62
lib/units/poorxy/index.js
Normal file
62
lib/units/poorxy/index.js
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user