[CORD-1549] Updating GUI extension
Change-Id: Ie376fb8bd7eb321a8a2448d64e5f7e086b15328b
diff --git a/conf/browsersync.conf.js b/conf/browsersync.conf.js
index 49936d4..06cb51a 100755
--- a/conf/browsersync.conf.js
+++ b/conf/browsersync.conf.js
@@ -1,4 +1,5 @@
const conf = require('./gulp.conf');
+const proxy = require('./proxy');
module.exports = function () {
return {
@@ -6,7 +7,15 @@
baseDir: [
conf.paths.tmp,
conf.paths.src
- ]
+ ],
+ middleware: function (req, res, next) {
+ if (req.url.indexOf('xosapi') !== -1 || req.url.indexOf('xos') !== -1 || req.url.indexOf('socket') !== -1) {
+ proxy.api.web(req, res);
+ }
+ else {
+ next();
+ }
+ }
},
open: false
};
diff --git a/conf/proxy.js b/conf/proxy.js
new file mode 100644
index 0000000..311dbcd
--- /dev/null
+++ b/conf/proxy.js
@@ -0,0 +1,18 @@
+const httpProxy = require('http-proxy');
+
+const target = process.env.PROXY || '192.168.46.100';
+
+const apiProxy = httpProxy.createProxyServer({
+ target: `http://${target}`
+});
+
+apiProxy.on('error', (error, req, res) => {
+ res.writeHead(500, {
+ 'Content-Type': 'text/plain'
+ });
+ console.error('[Proxy]', error);
+});
+
+module.exports = {
+ api: apiProxy
+};