blob: e8c38fadb222033bc0ca8320e0fb1f011a35e7c2 [file] [log] [blame]
Matteo Scandolod819c922016-12-02 14:06:14 -08001const conf = require('./gulp.conf');
Matteo Scandolo1aee1982017-02-17 08:33:23 -08002const httpProxy = require('http-proxy');
3
4// TODO move the proxy config in a separate file and share with browsersync.dist.js
5
6const proxy = httpProxy.createProxyServer({
7 target: 'http://xos.dev:9101'
8});
9
10proxy.on('error', function(error, req, res) {
11 res.writeHead(500, {
12 'Content-Type': 'text/plain'
13 });
14 console.error('[Proxy]', error);
15});
Matteo Scandolod819c922016-12-02 14:06:14 -080016
17module.exports = function () {
18 return {
19 server: {
20 baseDir: [
21 conf.paths.tmp,
22 conf.paths.src
Matteo Scandolo1aee1982017-02-17 08:33:23 -080023 ],
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 Scandolod819c922016-12-02 14:06:14 -080032 },
Matteo Scandolo1aee1982017-02-17 08:33:23 -080033 open: true
Matteo Scandolod819c922016-12-02 14:06:14 -080034 };
35};