]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/servers.ts
Set port if not specified in webfinger
[github/Chocobozzz/PeerTube.git] / server / middlewares / servers.ts
CommitLineData
69818c93
C
1import 'express-validator'
2import * as express from 'express'
0405ab52 3import { getHostWithPort } from '../helpers'
69818c93 4
e02643f3 5import { REMOTE_SCHEME } from '../initializers'
1ab844d8 6
69818c93 7function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
b09ce645
C
8 if (!req.body.hosts) return next()
9
49abbbbe
C
10 for (let i = 0; i < req.body.hosts.length; i++) {
11 const hostWithPort = getHostWithPort(req.body.hosts[i])
1ab844d8
C
12
13 // Problem with the url parsing?
49abbbbe 14 if (hostWithPort === null) {
1ab844d8
C
15 return res.sendStatus(500)
16 }
17
49abbbbe 18 req.body.hosts[i] = hostWithPort
1ab844d8
C
19 }
20
21 return next()
22}
23
1ab844d8
C
24// ---------------------------------------------------------------------------
25
65fcc311 26export {
d4f1e94c 27 setBodyHostsPort
65fcc311 28}