3 const constants = require('../initializers/constants')
5 const podsMiddleware = {
10 function setBodyHostsPort (req, res, next) {
11 if (!req.body.hosts) return next()
13 for (let i = 0; i < req.body.hosts.length; i++) {
14 const hostWithPort = getHostWithPort(req.body.hosts[i])
16 // Problem with the url parsing?
17 if (hostWithPort === null) {
18 return res.sendStatus(500)
21 req.body.hosts[i] = hostWithPort
27 function setBodyHostPort (req, res, next) {
28 if (!req.body.host) return next()
30 const hostWithPort = getHostWithPort(req.body.host)
32 // Problem with the url parsing?
33 if (hostWithPort === null) {
34 return res.sendStatus(500)
37 req.body.host = hostWithPort
42 // ---------------------------------------------------------------------------
44 module.exports = podsMiddleware
46 // ---------------------------------------------------------------------------
48 function getHostWithPort (host) {
49 const splitted = host.split(':')
51 // The port was not specified
52 if (splitted.length === 1) {
53 if (constants.REMOTE_SCHEME.HTTP === 'https') return host + ':443'