X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fservers.ts;h=ebfa03e6ca02ccc0747d93d4dfe0988140299be9;hb=d4d9bbc6f24522f5d63b0ab105a02f80ca98d702;hp=eaf9aa144a7806b9532b8356d1375543e9c1ec50;hpb=608624252466acf9f1d9ee1c1170bd4fe4d18d18;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index eaf9aa144..ebfa03e6c 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts @@ -1,7 +1,6 @@ -import 'express-validator' -import * as express from 'express' - -import { REMOTE_SCHEME } from '../initializers' +import express from 'express' +import { HttpStatusCode } from '../../shared/models/http/http-error-codes' +import { getHostWithPort } from '../helpers/express-utils' function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.body.hosts) return next() @@ -11,7 +10,10 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex // Problem with the url parsing? if (hostWithPort === null) { - return res.sendStatus(500) + return res.fail({ + status: HttpStatusCode.INTERNAL_SERVER_ERROR_500, + message: 'Could not parse hosts' + }) } req.body.hosts[i] = hostWithPort @@ -20,39 +22,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 }