]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/servers.ts
replace numbers with typed http status codes (#3409)
[github/Chocobozzz/PeerTube.git] / server / middlewares / servers.ts
1 import * as express from 'express'
2 import { getHostWithPort } from '../helpers/express-utils'
3 import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
4
5 function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.body.hosts) return next()
7
8 for (let i = 0; i < req.body.hosts.length; i++) {
9 const hostWithPort = getHostWithPort(req.body.hosts[i])
10
11 // Problem with the url parsing?
12 if (hostWithPort === null) {
13 return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
14 }
15
16 req.body.hosts[i] = hostWithPort
17 }
18
19 return next()
20 }
21
22 // ---------------------------------------------------------------------------
23
24 export {
25 setBodyHostsPort
26 }