aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/middlewares/pods.js
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/middlewares/pods.js')
-rw-r--r--server/middlewares/pods.js59
1 files changed, 0 insertions, 59 deletions
diff --git a/server/middlewares/pods.js b/server/middlewares/pods.js
deleted file mode 100644
index 2647f9ff0..000000000
--- a/server/middlewares/pods.js
+++ /dev/null
@@ -1,59 +0,0 @@
1'use strict'
2
3const constants = require('../initializers/constants')
4
5const podsMiddleware = {
6 setBodyHostsPort,
7 setBodyHostPort
8}
9
10function setBodyHostsPort (req, res, next) {
11 if (!req.body.hosts) return next()
12
13 for (let i = 0; i < req.body.hosts.length; i++) {
14 const hostWithPort = getHostWithPort(req.body.hosts[i])
15
16 // Problem with the url parsing?
17 if (hostWithPort === null) {
18 return res.sendStatus(500)
19 }
20
21 req.body.hosts[i] = hostWithPort
22 }
23
24 return next()
25}
26
27function setBodyHostPort (req, res, next) {
28 if (!req.body.host) return next()
29
30 const hostWithPort = getHostWithPort(req.body.host)
31
32 // Problem with the url parsing?
33 if (hostWithPort === null) {
34 return res.sendStatus(500)
35 }
36
37 req.body.host = hostWithPort
38
39 return next()
40}
41
42// ---------------------------------------------------------------------------
43
44module.exports = podsMiddleware
45
46// ---------------------------------------------------------------------------
47
48function getHostWithPort (host) {
49 const splitted = host.split(':')
50
51 // The port was not specified
52 if (splitted.length === 1) {
53 if (constants.REMOTE_SCHEME.HTTP === 'https') return host + ':443'
54
55 return host + ':80'
56 }
57
58 return host
59}