Matteo Scandolo | c46a82d | 2017-03-24 18:37:18 -0700 | [diff] [blame] | 1 | const httpProxy = require('http-proxy'); |
| 2 | |
| 3 | const target = process.env.PROXY || '192.168.46.100'; |
| 4 | |
| 5 | const apiProxy = httpProxy.createProxyServer({ |
| 6 | target: `http://${target}:9101` |
| 7 | }); |
| 8 | |
| 9 | const staticFilesProxy = httpProxy.createProxyServer({ |
| 10 | target: `http://${target}/spa` |
| 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 | }; |