mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +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:
@@ -9,7 +9,6 @@ var serveFavicon = require('serve-favicon')
|
||||
var serveStatic = require('serve-static')
|
||||
var csrf = require('csurf')
|
||||
var Promise = require('bluebird')
|
||||
var httpProxy = require('http-proxy')
|
||||
var compression = require('compression')
|
||||
|
||||
var logger = require('../../util/logger')
|
||||
@@ -29,11 +28,6 @@ module.exports = function(options) {
|
||||
var log = logger.createLogger('app')
|
||||
, app = express()
|
||||
, server = http.createServer(app)
|
||||
, proxy = httpProxy.createProxyServer()
|
||||
|
||||
proxy.on('error', function(err) {
|
||||
log.error('Proxy had an error', err.stack)
|
||||
})
|
||||
|
||||
app.use('/static/docs', markdownServe.middleware({
|
||||
rootDirectory: pathutil.root('node_modules/stf-docs')
|
||||
@@ -89,27 +83,6 @@ module.exports = function(options) {
|
||||
, authUrl: options.authUrl
|
||||
}))
|
||||
|
||||
// Proxied requests must come before any body parsers. These proxies are
|
||||
// here mainly for convenience, they should be replaced with proper reverse
|
||||
// proxies in production.
|
||||
app.all('/api/v1/s/image/*', function(req, res) {
|
||||
proxy.web(req, res, {
|
||||
target: options.storagePluginImageUrl
|
||||
})
|
||||
})
|
||||
|
||||
app.all('/api/v1/s/apk/*', function(req, res) {
|
||||
proxy.web(req, res, {
|
||||
target: options.storagePluginApkUrl
|
||||
})
|
||||
})
|
||||
|
||||
app.all('/api/v1/s/*', function(req, res) {
|
||||
proxy.web(req, res, {
|
||||
target: options.storageUrl
|
||||
})
|
||||
})
|
||||
|
||||
app.use(bodyParser.json())
|
||||
app.use(csrf())
|
||||
app.use(validator())
|
||||
|
||||
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