aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/pods.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/pods.ts')
-rw-r--r--server/helpers/custom-validators/pods.ts23
1 files changed, 16 insertions, 7 deletions
diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts
index 0519def52..f2ca520c0 100644
--- a/server/helpers/custom-validators/pods.ts
+++ b/server/helpers/custom-validators/pods.ts
@@ -1,9 +1,20 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2 2
3import { isArray, exists } from './misc' 3import { isArray, exists } from './misc'
4import { isTestInstance } from '../core-utils'
4 5
5function isHostValid (host: string) { 6function isHostValid (host: string) {
6 return exists(host) && validator.isURL(host) && host.split('://').length === 1 7 const isURLOptions = {
8 require_host: true,
9 require_tld: true
10 }
11
12 // We validate 'localhost', so we don't have the top level domain
13 if (isTestInstance()) {
14 isURLOptions.require_tld = false
15 }
16
17 return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
7} 18}
8 19
9function isEachUniqueHostValid (hosts: string[]) { 20function isEachUniqueHostValid (hosts: string[]) {
@@ -21,11 +32,9 @@ export {
21 isHostValid 32 isHostValid
22} 33}
23 34
24declare global { 35declare module 'express-validator' {
25 namespace ExpressValidator { 36 export interface Validator {
26 export interface Validator { 37 isEachUniqueHostValid
27 isEachUniqueHostValid 38 isHostValid
28 isHostValid
29 }
30 } 39 }
31} 40}