Apply dependencies update
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIServiceUtils.ts
index dabb5d474e88a78aebe5ea965b5b591e9f20246e..974d6fc4fb0ac16be896e62f4a43fbd06685437e 100644 (file)
@@ -5,6 +5,10 @@ import Utils from '../../../utils/Utils';
 import logger from '../../../utils/Logger';
 
 export class UIServiceUtils {
+  private constructor() {
+    // This is intentional
+  }
+
   public static handleProtocols = (
     protocols: Set<string>,
     request: IncomingMessage
@@ -33,4 +37,13 @@ export class UIServiceUtils {
     );
     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);
+  }
 }