Matteo Scandolo | f0446ed | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
Matteo Scandolo | f0446ed | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
Matteo Scandolo | f0446ed | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 6 | * http://www.apache.org/licenses/LICENSE-2.0 |
Matteo Scandolo | f0446ed | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 7 | * Unless required by applicable law or agreed to in writing, software |
| 8 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | * See the License for the specific language governing permissions and |
| 11 | * limitations under the License. |
| 12 | */ |
| 13 | |
Matteo Scandolo | c46a82d | 2017-03-24 18:37:18 -0700 | [diff] [blame] | 14 | const httpProxy = require('http-proxy'); |
| 15 | |
| 16 | const target = process.env.PROXY || '192.168.46.100'; |
| 17 | |
Matteo Scandolo | 22f8e82 | 2017-09-28 16:35:20 -0700 | [diff] [blame] | 18 | console.log(`proxy setup to: ${target}`); |
| 19 | |
| 20 | const proxy = httpProxy.createProxyServer({ |
| 21 | target: `http://${target}` |
Matteo Scandolo | c46a82d | 2017-03-24 18:37:18 -0700 | [diff] [blame] | 22 | }); |
| 23 | |
Matteo Scandolo | 22f8e82 | 2017-09-28 16:35:20 -0700 | [diff] [blame] | 24 | proxy.on('error', (error, req, res) => { |
Matteo Scandolo | c46a82d | 2017-03-24 18:37:18 -0700 | [diff] [blame] | 25 | res.writeHead(500, { |
| 26 | 'Content-Type': 'text/plain' |
| 27 | }); |
| 28 | console.error('[Proxy]', error); |
| 29 | }); |
| 30 | |
Matteo Scandolo | 22f8e82 | 2017-09-28 16:35:20 -0700 | [diff] [blame] | 31 | module.exports = proxy; |