Files
stf-DeviceFarmer/lib/units/poorxy/index.js
Denis Barbaron 2f54e40206 Upgrading STF for security reasons (#813)
* Upgrading STF for security reasons

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* update semaphore files

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* upgrading STF for security reasons v2

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* update yarn.lock file

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

---------

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
2024-11-22 11:41:20 +01:00

76 lines
1.7 KiB
JavaScript

/**
* Copyright © 2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
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)
app.disable('x-powered-by')
;['/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)
}