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