Working gateway

Change-Id: I8ca690fe9d1b7f8e20b438df1ddd48d6b2f99326
diff --git a/src/routes/core_proxy.js b/src/routes/core_proxy.js
new file mode 100644
index 0000000..0290347
--- /dev/null
+++ b/src/routes/core_proxy.js
@@ -0,0 +1,48 @@
+(function () {
+  'use strict';
+
+  const request = require('superagent');
+  const logger = require('../config/logger.js');
+
+  module.exports = function(app) {
+
+    const proxyRequest = (req, res) => {
+
+      const config = require('../config/config.js').xos;
+      // pick the correct method from superAgent
+      const makeReq = request[req.method.toLowerCase()];
+
+      // start the request
+      let sentReq = makeReq(`${config.host}:${config.port}${req.url}`);
+      
+      // if needed add a body to the request
+      if(req.method === 'POST' || req.method === 'PUT') {
+        sentReq = sentReq
+          .send(req.body)
+      }
+
+      // extend with auth info
+      sentReq = sentReq
+        .set('x-csrftoken', req.headers['x-csrftoken'] || null)
+        .set('cookie', req.headers.cookie || null)
+
+      // handle response
+      sentReq
+        .end((err, r) => {
+          if(err) {
+            logger.log('error', err);
+            return res.status(500).send(err);
+          }
+          logger.log('debug', r.status, r.body);
+          return res.status(r.status).type('json').send(r.body);
+        });
+    };
+
+    app.all('/api/core', proxyRequest);
+    app.all('/api/core/*', proxyRequest);
+    app.all('/api/services', proxyRequest);
+    app.all('/api/services/*', proxyRequest);
+    app.all('/api/utility', proxyRequest);
+    app.all('/api/utility/*', proxyRequest);
+  };
+})();
\ No newline at end of file