aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/pods.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/pods.ts')
-rw-r--r--server/middlewares/pods.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/server/middlewares/pods.ts b/server/middlewares/pods.ts
new file mode 100644
index 000000000..e405f265e
--- /dev/null
+++ b/server/middlewares/pods.ts
@@ -0,0 +1,57 @@
1'use strict'
2
3const constants = require('../initializers/constants')
4
5function setBodyHostsPort (req, res, next) {
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(500)
14 }
15
16 req.body.hosts[i] = hostWithPort
17 }
18
19 return next()
20}
21
22function setBodyHostPort (req, res, next) {
23 if (!req.body.host) return next()
24
25 const hostWithPort = getHostWithPort(req.body.host)
26
27 // Problem with the url parsing?
28 if (hostWithPort === null) {
29 return res.sendStatus(500)
30 }
31
32 req.body.host = hostWithPort
33
34 return next()
35}
36
37// ---------------------------------------------------------------------------
38
39export {
40 setBodyHostsPort,
41 setBodyHostPort
42}
43
44// ---------------------------------------------------------------------------
45
46function getHostWithPort (host) {
47 const splitted = host.split(':')
48
49 // The port was not specified
50 if (splitted.length === 1) {
51 if (constants.REMOTE_SCHEME.HTTP === 'https') return host + ':443'
52
53 return host + ':80'
54 }
55
56 return host
57}