diff --git a/README.md b/README.md index 3b575217c..8cccbe573 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,10 @@ The Self Service UI for the [ManageIQ](http://github.com/ManageIQ/manageiq) proj - In the `manageiq-ui-self_service` directory, start the development version of the self service UI with `gulp serve-dev`, which will start the UI listening on http://localhost:3001, and talking to the REST API at - http://localhost:3000. This command will also open a browser page to - http://localhost:3001/self_service/login . + http://[::1]:3000. This command will also open a browser page to + http://localhost:3001/self_service/login. + The REST API host can be overriden via a PROXY\_HOST environment variable, for + example: `PROXY_HOST=127.0.0.1:3000 gulp serve-dev`. ## Deployment diff --git a/package.json b/package.json index 37ba4eb6b..ee85053e1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "dateformat": "^1.0.11", "debug": "^2.1.3", "del": "^2.0.2", - "express-http-proxy": "^0.6.0", "glob": "^5.0.3", "gulp": "^3.8.11", "gulp-angular-gettext": "^2.1.0", @@ -92,6 +91,7 @@ "dependencies": { "body-parser": "^1.12.2", "express": "^4.12.3", + "http-proxy": "^1.13.2", "morgan": "^1.5.2", "serve-favicon": "^2.2.0" }, diff --git a/server/app.js b/server/app.js index 975eb5d3d..be321aa9b 100644 --- a/server/app.js +++ b/server/app.js @@ -2,7 +2,7 @@ 'use strict'; var express = require('express'); -var proxy = require('express-http-proxy'); +var httpProxy = require('http-proxy'); var app = express(); var router = express.Router(); var bodyParser = require('body-parser'); @@ -13,15 +13,33 @@ var four0four = require('./utils/404')(); var url = require('url'); var environment = process.env.NODE_ENV; +var PROXY_HOST = process.env.PROXY_HOST || '[::1]:3000'; -app.use('/api', proxy('127.0.0.1:3000', { - forwardPath: function(req, res) { - var path = '/api' + url.parse(req.url).path; +var PROXY_TARGET = 'http://' + PROXY_HOST + '/api'; +var proxy_error_handler = function(req, res) { + return function(err, data) { + if (!err) + return; - console.log('PROXY: http://127.0.0.1:3000' + path); - return path; + res.writeHead(500, { + 'Content-Type': 'text/plain' + }); + + res.end('Something went wrong: ' + err); + console.error(err); } -})); +} + +var proxy = httpProxy.createProxyServer({ + target: PROXY_TARGET, +}); + +app.use('/api', function(req, res) { + var path = url.parse(req.url).path; + + console.log('PROXY: ' + PROXY_TARGET + path); + proxy.web(req, res, proxy_error_handler(req, res)); +}); router.use(favicon(__dirname + '/favicon.ico')); router.use(bodyParser.urlencoded({ extended: true })); @@ -50,6 +68,12 @@ switch (environment) { router.use(express.static('./client/')); router.use(express.static('./tmp')); router.use(express.static('./client/assets')); + var pictureProxy = httpProxy.createProxyServer({ + target: 'http://' + PROXY_HOST + '/pictures', + }); + app.use('/pictures', function(req, res) { + pictureProxy.web(req, res, proxy_error_handler(req, res)); + }); app.use(express.static('./')); // Any invalid calls for templateUrls are under app/* and should return 404 router.use('/app/*', function(req, res) {