aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/servers.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 11:00:25 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit608624252466acf9f1d9ee1c1170bd4fe4d18d18 (patch)
tree47eab55bb5421b7fe88e0b2ac743a436fd9561cf /server/middlewares/servers.ts
parent51548b31815c6f96f314ae96588a9adca150519d (diff)
downloadPeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.gz
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.zst
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.zip
Rename Pod -> Server
Diffstat (limited to 'server/middlewares/servers.ts')
-rw-r--r--server/middlewares/servers.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts
new file mode 100644
index 000000000..eaf9aa144
--- /dev/null
+++ b/server/middlewares/servers.ts
@@ -0,0 +1,58 @@
1import 'express-validator'
2import * as express from 'express'
3
4import { REMOTE_SCHEME } from '../initializers'
5
6function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
7 if (!req.body.hosts) return next()
8
9 for (let i = 0; i < req.body.hosts.length; i++) {
10 const hostWithPort = getHostWithPort(req.body.hosts[i])
11
12 // Problem with the url parsing?
13 if (hostWithPort === null) {
14 return res.sendStatus(500)
15 }
16
17 req.body.hosts[i] = hostWithPort
18 }
19
20 return next()
21}
22
23function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) {
24 if (!req.body.host) return next()
25
26 const hostWithPort = getHostWithPort(req.body.host)
27
28 // Problem with the url parsing?
29 if (hostWithPort === null) {
30 return res.sendStatus(500)
31 }
32
33 req.body.host = hostWithPort
34
35 return next()
36}
37
38// ---------------------------------------------------------------------------
39
40export {
41 setBodyHostsPort,
42 setBodyHostPort
43}
44
45// ---------------------------------------------------------------------------
46
47function getHostWithPort (host: string) {
48 const splitted = host.split(':')
49
50 // The port was not specified
51 if (splitted.length === 1) {
52 if (REMOTE_SCHEME.HTTP === 'https') return host + ':443'
53
54 return host + ':80'
55 }
56
57 return host
58}