mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
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')
|
|
var app = express()
|
|
var server = http.createServer(app)
|
|
var 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)
|
|
|
|
;['/static/auth/*', '/auth/*'].forEach(function(route) {
|
|
app.all(route, function(req, res) {
|
|
proxy.web(req, res, {
|
|
target: options.authUrl
|
|
})
|
|
})
|
|
})
|
|
|
|
;['/s/image/*'].forEach(function(route) {
|
|
app.all(route, function(req, res) {
|
|
proxy.web(req, res, {
|
|
target: options.storagePluginImageUrl
|
|
})
|
|
})
|
|
})
|
|
|
|
;['/s/apk/*'].forEach(function(route) {
|
|
app.all(route, function(req, res) {
|
|
proxy.web(req, res, {
|
|
target: options.storagePluginApkUrl
|
|
})
|
|
})
|
|
})
|
|
|
|
;['/s/*'].forEach(function(route) {
|
|
app.all(route, function(req, res) {
|
|
proxy.web(req, res, {
|
|
target: options.storageUrl
|
|
})
|
|
})
|
|
})
|
|
|
|
;['/api/*'].forEach(function(route) {
|
|
app.all(route, function(req, res) {
|
|
proxy.web(req, res, {
|
|
target: options.apiUrl
|
|
})
|
|
})
|
|
})
|
|
app.use(function(req, res) {
|
|
proxy.web(req, res, {
|
|
target: options.appUrl
|
|
})
|
|
})
|
|
|
|
server.listen(options.port)
|
|
log.info('Listening on port %d', options.port)
|
|
}
|