Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 1 | const httpProxy = require('http-proxy'); |
| 2 | |
Matteo Scandolo | ad8df67 | 2017-03-29 22:34:38 -0700 | [diff] [blame] | 3 | const target = process.env.PROXY || '192.168.46.100'; |
| 4 | |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 5 | const apiProxy = httpProxy.createProxyServer({ |
Matteo Scandolo | ad8df67 | 2017-03-29 22:34:38 -0700 | [diff] [blame] | 6 | target: `http://${target}` |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 7 | }); |
| 8 | |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 9 | apiProxy.on('error', (error, req, res) => { |
| 10 | res.writeHead(500, { |
| 11 | 'Content-Type': 'text/plain' |
| 12 | }); |
| 13 | console.error('[Proxy]', error); |
| 14 | }); |
| 15 | |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 16 | module.exports = { |
| 17 | api: apiProxy, |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 18 | }; |