From 5bfe684e76d32a7745671635f8a75f932bd522e4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Feb 2023 16:36:04 +0100 Subject: Move webfinger controller in well known router --- server/controllers/index.ts | 1 - server/controllers/webfinger.ts | 44 ---------------------------------------- server/controllers/well-known.ts | 31 +++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 46 deletions(-) delete mode 100644 server/controllers/webfinger.ts (limited to 'server/controllers') diff --git a/server/controllers/index.ts b/server/controllers/index.ts index eaa2dd7c8..09d657aca 100644 --- a/server/controllers/index.ts +++ b/server/controllers/index.ts @@ -11,5 +11,4 @@ export * from './plugins' export * from './services' export * from './static' export * from './tracker' -export * from './webfinger' export * from './well-known' diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts deleted file mode 100644 index 29ce01166..000000000 --- a/server/controllers/webfinger.ts +++ /dev/null @@ -1,44 +0,0 @@ -import cors from 'cors' -import express from 'express' -import { WEBSERVER } from '@server/initializers/constants' -import { asyncMiddleware } from '../middlewares' -import { webfingerValidator } from '../middlewares/validators' - -const webfingerRouter = express.Router() - -webfingerRouter.use(cors()) - -webfingerRouter.get('/.well-known/webfinger', - asyncMiddleware(webfingerValidator), - webfingerController -) - -// --------------------------------------------------------------------------- - -export { - webfingerRouter -} - -// --------------------------------------------------------------------------- - -function webfingerController (req: express.Request, res: express.Response) { - const actor = res.locals.actorUrl - - const json = { - subject: req.query.resource, - aliases: [ actor.url ], - links: [ - { - rel: 'self', - type: 'application/activity+json', - href: actor.url - }, - { - rel: 'http://ostatus.org/schema/1.0/subscribe', - template: WEBSERVER.URL + '/remote-interaction?uri={uri}' - } - ] - } - - return res.json(json) -} diff --git a/server/controllers/well-known.ts b/server/controllers/well-known.ts index ce5883571..bb9acfb37 100644 --- a/server/controllers/well-known.ts +++ b/server/controllers/well-known.ts @@ -1,16 +1,21 @@ import cors from 'cors' import express from 'express' import { join } from 'path' +import { asyncMiddleware, handleStaticError, webfingerValidator } from '@server/middlewares' import { root } from '@shared/core-utils' import { CONFIG } from '../initializers/config' import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' import { cacheRoute } from '../middlewares/cache/cache' -import { handleStaticError } from '@server/middlewares' const wellKnownRouter = express.Router() wellKnownRouter.use(cors()) +wellKnownRouter.get('/.well-known/webfinger', + asyncMiddleware(webfingerValidator), + webfingerController +) + wellKnownRouter.get('/.well-known/security.txt', cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), (_, res: express.Response) => { @@ -81,3 +86,27 @@ wellKnownRouter.use('/.well-known/', export { wellKnownRouter } + +// --------------------------------------------------------------------------- + +function webfingerController (req: express.Request, res: express.Response) { + const actor = res.locals.actorUrl + + const json = { + subject: req.query.resource, + aliases: [ actor.url ], + links: [ + { + rel: 'self', + type: 'application/activity+json', + href: actor.url + }, + { + rel: 'http://ostatus.org/schema/1.0/subscribe', + template: WEBSERVER.URL + '/remote-interaction?uri={uri}' + } + ] + } + + return res.json(json) +} -- cgit v1.2.3