Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 1 | const httpProxy = require('http-proxy'); |
| 2 | |
Matteo Scandolo | 47c53fc | 2017-03-23 14:11:32 -0700 | [diff] [blame] | 3 | const target = process.env.PROXY || '192.168.46.100'; |
| 4 | |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 5 | const proxy = httpProxy.createProxyServer({ |
Matteo Scandolo | a338531 | 2017-05-10 09:52:36 -0700 | [diff] [blame] | 6 | target: `http://${target}` |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 7 | }); |
| 8 | |
Matteo Scandolo | 98b5f5d | 2017-03-17 17:09:05 -0700 | [diff] [blame] | 9 | const extensionsProxy = httpProxy.createProxyServer({ |
Matteo Scandolo | f818312 | 2017-04-24 15:03:00 -0700 | [diff] [blame] | 10 | target: `http://${target}/xos/` |
Matteo Scandolo | 98b5f5d | 2017-03-17 17:09:05 -0700 | [diff] [blame] | 11 | }); |
| 12 | |
Matteo Scandolo | a338531 | 2017-05-10 09:52:36 -0700 | [diff] [blame] | 13 | const socketProxy = httpProxy.createProxyServer({ |
| 14 | target: `http://${target}/` |
| 15 | }); |
| 16 | |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 17 | proxy.on('error', function(error, req, res) { |
Matteo Scandolo | a338531 | 2017-05-10 09:52:36 -0700 | [diff] [blame] | 18 | res.writeHead(500, {'Content-Type': 'text/plain'}); |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 19 | console.error('[Proxy]', error); |
| 20 | }); |
| 21 | |
Matteo Scandolo | a338531 | 2017-05-10 09:52:36 -0700 | [diff] [blame] | 22 | extensionsProxy.on('error', function(error, req, res) { |
| 23 | res.writeHead(500, {'Content-Type': 'text/plain'}); |
| 24 | console.error('[extensionsProxy]', error); |
| 25 | }); |
| 26 | |
| 27 | socketProxy.on('error', function(error, req, res) { |
| 28 | res.writeHead(500, {'Content-Type': 'text/plain'}); |
| 29 | console.error('[socketProxy]', error); |
| 30 | }); |
| 31 | |
Matteo Scandolo | 98b5f5d | 2017-03-17 17:09:05 -0700 | [diff] [blame] | 32 | module.exports = { |
| 33 | proxy, |
Matteo Scandolo | a338531 | 2017-05-10 09:52:36 -0700 | [diff] [blame] | 34 | extensionsProxy, |
| 35 | socketProxy |
Matteo Scandolo | 98b5f5d | 2017-03-17 17:09:05 -0700 | [diff] [blame] | 36 | }; |