1 import { REMOTE_SCHEME } from '../initializers'
3 function setBodyHostsPort (req, res, next) {
4 if (!req.body.hosts) return next()
6 for (let i = 0; i < req.body.hosts.length; i++) {
7 const hostWithPort = getHostWithPort(req.body.hosts[i])
9 // Problem with the url parsing?
10 if (hostWithPort === null) {
11 return res.sendStatus(500)
14 req.body.hosts[i] = hostWithPort
20 function setBodyHostPort (req, res, next) {
21 if (!req.body.host) return next()
23 const hostWithPort = getHostWithPort(req.body.host)
25 // Problem with the url parsing?
26 if (hostWithPort === null) {
27 return res.sendStatus(500)
30 req.body.host = hostWithPort
35 // ---------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------
44 function getHostWithPort (host) {
45 const splitted = host.split(':')
47 // The port was not specified
48 if (splitted.length === 1) {
49 if (REMOTE_SCHEME.HTTP === 'https') return host + ':443'