diff options
Diffstat (limited to 'server/helpers/custom-validators/pods.ts')
-rw-r--r-- | server/helpers/custom-validators/pods.ts | 23 |
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | 2 | ||
3 | import { isArray, exists } from './misc' | 3 | import { isArray, exists } from './misc' |
4 | import { isTestInstance } from '../core-utils' | ||
4 | 5 | ||
5 | function isHostValid (host: string) { | 6 | function 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 | ||
9 | function isEachUniqueHostValid (hosts: string[]) { | 20 | function isEachUniqueHostValid (hosts: string[]) { |
@@ -21,11 +32,9 @@ export { | |||
21 | isHostValid | 32 | isHostValid |
22 | } | 33 | } |
23 | 34 | ||
24 | declare global { | 35 | declare 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 | } |