3 const constants = require('../initializers/constants')
5 function setBodyHostsPort (req, res, next) {
6 if (!req.body.hosts) return next()
8 for (let i = 0; i < req.body.hosts.length; i++) {
9 const hostWithPort = getHostWithPort(req.body.hosts[i])
11 // Problem with the url parsing?
12 if (hostWithPort === null) {
13 return res.sendStatus(500)
16 req.body.hosts[i] = hostWithPort
22 function setBodyHostPort (req, res, next) {
23 if (!req.body.host) return next()
25 const hostWithPort = getHostWithPort(req.body.host)
27 // Problem with the url parsing?
28 if (hostWithPort === null) {
29 return res.sendStatus(500)
32 req.body.host = hostWithPort
37 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
46 function getHostWithPort (host) {
47 const splitted = host.split(':')
49 // The port was not specified
50 if (splitted.length === 1) {
51 if (constants.REMOTE_SCHEME.HTTP === 'https') return host + ':443'