aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/pods.js
blob: 8bb3733ffae4465afd4eac17131b1f288c695cba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict'

const validator = require('express-validator').validator

const miscValidators = require('./misc')

const podsValidators = {
  isEachUniqueHostValid,
  isHostValid
}

function isHostValid (host) {
  return validator.isURL(host) && host.split('://').length === 1
}

function isEachUniqueHostValid (hosts) {
  return miscValidators.isArray(hosts) &&
    hosts.length !== 0 &&
    hosts.every(function (host) {
      return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
    })
}

// ---------------------------------------------------------------------------

module.exports = podsValidators