Avoid strings concatenation
[e-mobility-charging-stations-simulator.git] / test / robohydra / plugins / wsServer / index.js
index d4ab6b8dfad79f4f1bb319265d0a59171b0913d0..dfb4268989fe05d617a9b16297d709a757ba42e4 100644 (file)
@@ -1,8 +1,11 @@
-const RoboHydraHead = require('robohydra').heads.RoboHydraHead;
-const RoboHydraWebSocketHead = require('robohydra').heads.RoboHydraWebSocketHead;
-const RoboHydraWebSocketHeadProxy = require('robohydra').heads.RoboHydraWebSocketHeadProxy;
+// eslint-disable-next-line n/no-unpublished-require
+const RoboHydra = require('robohydra');
+const RoboHydraHead = RoboHydra.heads.RoboHydraHead;
+const RoboHydraWebSocketHead = RoboHydra.heads.RoboHydraWebSocketHead;
+const RoboHydraWebSocketHeadProxy = RoboHydra.heads.RoboHydraWebSocketHeadProxy;
 
-exports.getBodyParts = function(conf) {
+// eslint-disable-next-line no-unused-vars
+exports.getBodyParts = function (conf) {
   let wsSocket;
   return {
     heads: [
@@ -10,7 +13,7 @@ exports.getBodyParts = function(conf) {
         name: 'message',
         path: '/message',
         method: 'POST',
-        handler: function(req, res) {
+        handler: function (req, res) {
           const msg = JSON.stringify(req.body);
           if (wsSocket) {
             wsSocket.send(msg);
@@ -18,42 +21,42 @@ exports.getBodyParts = function(conf) {
           } else {
             res.send('Cannot send message, no opened websocket found');
           }
-        }
+        },
       }),
 
       new RoboHydraHead({
         name: 'close',
         path: '/close',
         method: 'GET',
-        handler: function(req, res) {
+        handler: function (req, res) {
           if (wsSocket) {
             wsSocket.close();
             res.send('Websocket closed');
           } else {
             res.send('Cannot close websocket, no opened websocket found');
           }
-        }
+        },
       }),
 
       new RoboHydraWebSocketHeadProxy({
         name: 'proxy',
         mountPath: '/proxy',
         proxyTo: 'ws://server.example.com',
-        preProcessor: function(data) {
-          console.log('From the client: ' + data);
+        preProcessor: function (data) {
+          console.info(`From the client: ${data}`);
+        },
+        postProcessor: function (data) {
+          console.info(`From the server: ${data}`);
         },
-        postProcessor: function(data) {
-          console.log('From the server: ' + data);
-        }
       }),
 
       new RoboHydraWebSocketHead({
         name: 'WS Server',
         path: '/.*',
-        handler: function(req, socket) {
+        handler: function (req, socket) {
           wsSocket = socket;
-        }
-      })
-    ]
+        },
+      }),
+    ],
   };
 };