From 0405ab52dc0f445b88f8de76e30d6e6719196023 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Dec 2017 14:21:14 +0100 Subject: Set port if not specified in webfinger --- server/middlewares/servers.ts | 16 +--------------- server/middlewares/validators/webfinger.ts | 4 ++-- 2 files changed, 3 insertions(+), 17 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index 488f9c368..87bbe9fd7 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts @@ -1,5 +1,6 @@ import 'express-validator' import * as express from 'express' +import { getHostWithPort } from '../helpers' import { REMOTE_SCHEME } from '../initializers' @@ -25,18 +26,3 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex export { setBodyHostsPort } - -// --------------------------------------------------------------------------- - -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 -} diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 2c8351799..894c72498 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { query } from 'express-validator/check' -import { logger } from '../../helpers' +import { getHostWithPort, logger } from '../../helpers' import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' import { ActorModel } from '../../models/activitypub/actor' import { areValidationErrors } from './utils' @@ -14,7 +14,7 @@ const webfingerValidator = [ if (areValidationErrors(req, res)) return // Remove 'acct:' from the beginning of the string - const nameWithHost = req.query.resource.substr(5) + const nameWithHost = getHostWithPort(req.query.resource.substr(5)) const [ name ] = nameWithHost.split('@') const actor = await ActorModel.loadLocalByName(name) -- cgit v1.2.3