Version 1.1.67
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIServiceUtils.ts
index dabb5d474e88a78aebe5ea965b5b591e9f20246e..cf89b0c60598c2625b691288b144819c9e52c209 100644 (file)
@@ -1,10 +1,14 @@
-import { Protocol, ProtocolVersion } from '../../../types/UIProtocol';
-
 import { IncomingMessage } from 'http';
-import Utils from '../../../utils/Utils';
+
+import { Protocol, ProtocolVersion } from '../../../types/UIProtocol';
 import logger from '../../../utils/Logger';
+import Utils from '../../../utils/Utils';
 
 export class UIServiceUtils {
+  private constructor() {
+    // This is intentional
+  }
+
   public static handleProtocols = (
     protocols: Set<string>,
     request: IncomingMessage
@@ -28,9 +32,18 @@ export class UIServiceUtils {
     }
     logger.error(
       `${Utils.logPrefix(
-        ' UI WebSocket Server:'
+        ' UI WebSocket Server |'
       )} Unsupported protocol: ${protocol} or protocol version: ${version}`
     );
     return false;
   };
+
+  public static isLoopback(address: string): boolean {
+    const isLoopbackRegExp = new RegExp(
+      // eslint-disable-next-line no-useless-escape
+      /^localhost$|^127(?:\.\d+){0,2}\.\d+$|^(?:0*\:)*?:?0*1$/,
+      'i'
+    );
+    return isLoopbackRegExp.test(address);
+  }
 }