1 import 'express-validator'
2 import * as express from 'express'
4 import { REMOTE_SCHEME } from '../initializers'
6 function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
7 if (!req.body.hosts) return next()
9 for (let i = 0; i < req.body.hosts.length; i++) {
10 const hostWithPort = getHostWithPort(req.body.hosts[i])
12 // Problem with the url parsing?
13 if (hostWithPort === null) {
14 return res.sendStatus(500)
17 req.body.hosts[i] = hostWithPort
23 // ---------------------------------------------------------------------------
29 // ---------------------------------------------------------------------------
31 function getHostWithPort (host: string) {
32 const splitted = host.split(':')
34 // The port was not specified
35 if (splitted.length === 1) {
36 if (REMOTE_SCHEME.HTTP === 'https') return host + ':443'