]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/pods.ts
Add follow tabs
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / pods.ts
index 0519def52607b18d2e9bba468e143df47c0fa404..d5021bf38dbf5b8f553af001b87e5fe06a59128e 100644 (file)
@@ -1,9 +1,21 @@
 import * as validator from 'validator'
+import 'express-validator'
 
 import { isArray, exists } from './misc'
+import { isTestInstance } from '../core-utils'
 
 function isHostValid (host: string) {
-  return exists(host) && validator.isURL(host) && host.split('://').length === 1
+  const isURLOptions = {
+    require_host: true,
+    require_tld: true
+  }
+
+  // We validate 'localhost', so we don't have the top level domain
+  if (isTestInstance()) {
+    isURLOptions.require_tld = false
+  }
+
+  return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
 }
 
 function isEachUniqueHostValid (hosts: string[]) {
@@ -20,12 +32,3 @@ export {
   isEachUniqueHostValid,
   isHostValid
 }
-
-declare global {
-  namespace ExpressValidator {
-    export interface Validator {
-      isEachUniqueHostValid
-      isHostValid
-    }
-  }
-}