Set port if not specified in webfinger
[oweals/peertube.git] / server / middlewares / servers.ts
1 import 'express-validator'
2 import * as express from 'express'
3 import { getHostWithPort } from '../helpers'
4
5 import { REMOTE_SCHEME } from '../initializers'
6
7 function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
8   if (!req.body.hosts) return next()
9
10   for (let i = 0; i < req.body.hosts.length; i++) {
11     const hostWithPort = getHostWithPort(req.body.hosts[i])
12
13     // Problem with the url parsing?
14     if (hostWithPort === null) {
15       return res.sendStatus(500)
16     }
17
18     req.body.hosts[i] = hostWithPort
19   }
20
21   return next()
22 }
23
24 // ---------------------------------------------------------------------------
25
26 export {
27   setBodyHostsPort
28 }