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 function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) {
24 if (!req.body.host) return next()
26 const hostWithPort = getHostWithPort(req.body.host)
28 // Problem with the url parsing?
29 if (hostWithPort === null) {
30 return res.sendStatus(500)
33 req.body.host = hostWithPort
38 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
47 function getHostWithPort (host: string) {
48 const splitted = host.split(':')
50 // The port was not specified
51 if (splitted.length === 1) {
52 if (REMOTE_SCHEME.HTTP === 'https') return host + ':443'