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 | |
| 9 | const staticFilesProxy = httpProxy.createProxyServer({ |
Matteo Scandolo | ad8df67 | 2017-03-29 22:34:38 -0700 | [diff] [blame] | 10 | target: `http://${target}/spa` |
Matteo Scandolo | e19fa10 | 2017-03-09 15:38:59 -0800 | [diff] [blame] | 11 | }); |
| 12 | |
| 13 | apiProxy.on('error', (error, req, res) => { |
| 14 | res.writeHead(500, { |
| 15 | 'Content-Type': 'text/plain' |
| 16 | }); |
| 17 | console.error('[Proxy]', error); |
| 18 | }); |
| 19 | |
| 20 | staticFilesProxy.on('error', (error, req, res) => { |
| 21 | res.writeHead(500, { |
| 22 | 'Content-Type': 'text/plain' |
| 23 | }); |
| 24 | console.error('[Proxy]', error); |
| 25 | }); |
| 26 | |
| 27 | module.exports = { |
| 28 | api: apiProxy, |
| 29 | static: staticFilesProxy |
| 30 | }; |