From 5bfe684e76d32a7745671635f8a75f932bd522e4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Feb 2023 16:36:04 +0100 Subject: [PATCH] Move webfinger controller in well known router --- server.ts | 2 -- server/controllers/index.ts | 1 - server/controllers/webfinger.ts | 44 -------------------------------- server/controllers/well-known.ts | 31 +++++++++++++++++++++- 4 files changed, 30 insertions(+), 48 deletions(-) delete mode 100644 server/controllers/webfinger.ts diff --git a/server.ts b/server.ts index f6a153fb7..d1ac2d092 100644 --- a/server.ts +++ b/server.ts @@ -109,7 +109,6 @@ import { servicesRouter, objectStorageProxyRouter, pluginsRouter, - webfingerRouter, trackerRouter, createWebsocketTrackerServer, botsRouter, @@ -231,7 +230,6 @@ app.use('/', pluginsRouter) app.use('/', activityPubRouter) app.use('/', feedsRouter) -app.use('/', webfingerRouter) app.use('/', trackerRouter) app.use('/', botsRouter) 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) +}