diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/middlewares/pods.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-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.js | 59 |
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 | |||
3 | const constants = require('../initializers/constants') | ||
4 | |||
5 | const podsMiddleware = { | ||
6 | setBodyHostsPort, | ||
7 | setBodyHostPort | ||
8 | } | ||
9 | |||
10 | function 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 | |||
27 | function 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 | |||
44 | module.exports = podsMiddleware | ||
45 | |||
46 | // --------------------------------------------------------------------------- | ||
47 | |||
48 | function 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 | } | ||