Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 1 | const conf = require('./gulp.conf'); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame^] | 2 | const httpProxy = require('http-proxy'); |
| 3 | |
| 4 | // TODO move the proxy config in a separate file and share with browsersync.dist.js |
| 5 | |
| 6 | const proxy = httpProxy.createProxyServer({ |
| 7 | target: 'http://xos.dev:9101' |
| 8 | }); |
| 9 | |
| 10 | proxy.on('error', function(error, req, res) { |
| 11 | res.writeHead(500, { |
| 12 | 'Content-Type': 'text/plain' |
| 13 | }); |
| 14 | console.error('[Proxy]', error); |
| 15 | }); |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 16 | |
| 17 | module.exports = function () { |
| 18 | return { |
| 19 | server: { |
| 20 | baseDir: [ |
| 21 | conf.paths.tmp, |
| 22 | conf.paths.src |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame^] | 23 | ], |
| 24 | middleware: function(req, res, next){ |
| 25 | if (req.url.indexOf('xosapi') !== -1) { |
| 26 | proxy.web(req, res); |
| 27 | } |
| 28 | else{ |
| 29 | next(); |
| 30 | } |
| 31 | } |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 32 | }, |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame^] | 33 | open: true |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 34 | }; |
| 35 | }; |