]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/servers.ts
Add more info logging
[github/Chocobozzz/PeerTube.git] / server / middlewares / servers.ts
index eaf9aa144a7806b9532b8356d1375543e9c1ec50..c52f4685b94785b94f10e4e65aca0f5ff3fcfc22 100644 (file)
@@ -1,7 +1,6 @@
-import 'express-validator'
 import * as express from 'express'
-
-import { REMOTE_SCHEME } from '../initializers'
+import 'express-validator'
+import { getHostWithPort } from '../helpers/express-utils'
 
 function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
   if (!req.body.hosts) return next()
@@ -20,39 +19,8 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex
   return next()
 }
 
-function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) {
-  if (!req.body.host) return next()
-
-  const hostWithPort = getHostWithPort(req.body.host)
-
-  // Problem with the url parsing?
-  if (hostWithPort === null) {
-    return res.sendStatus(500)
-  }
-
-  req.body.host = hostWithPort
-
-  return next()
-}
-
 // ---------------------------------------------------------------------------
 
 export {
-  setBodyHostsPort,
-  setBodyHostPort
-}
-
-// ---------------------------------------------------------------------------
-
-function getHostWithPort (host: string) {
-  const splitted = host.split(':')
-
-  // The port was not specified
-  if (splitted.length === 1) {
-    if (REMOTE_SCHEME.HTTP === 'https') return host + ':443'
-
-    return host + ':80'
-  }
-
-  return host
+  setBodyHostsPort
 }