From 7e6601867f08b31cc3ee4373ec748ac1aba2f6cf Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 22 Oct 2024 08:50:02 +0300 Subject: vnext: RFC 6415: Web Host Metadata --- vnext/server/app.js | 6 ++++++ vnext/server/middleware/host-meta.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 vnext/server/middleware/host-meta.js (limited to 'vnext/server') diff --git a/vnext/server/app.js b/vnext/server/app.js index b2ba4cf6..f8beb933 100644 --- a/vnext/server/app.js +++ b/vnext/server/app.js @@ -13,6 +13,7 @@ import { instance } from './middleware/mastodon' import path from 'path' import { webhook, webhookPath } from './durov' import { webfinger } from './middleware/webfinger' +import { jsonMeta, xmlMeta } from './middleware/host-meta' // initialize the application and create the routes export const app = express() @@ -25,6 +26,11 @@ router.get('/api/v2/oembed', oembed) router.get('/api/v2/urlexpand', urlExpand) router.get('/api/apps/android/releases', releases) +// Web Host Metadata + +router.get('/.well-known/host-meta', xmlMeta) +router.get('/.well-known/host-meta.json', jsonMeta) + // WebFinger router.get('/.well-known/webfinger', webfinger) diff --git a/vnext/server/middleware/host-meta.js b/vnext/server/middleware/host-meta.js new file mode 100644 index 00000000..eec7d3e3 --- /dev/null +++ b/vnext/server/middleware/host-meta.js @@ -0,0 +1,30 @@ +import config from 'config' + +const baseURL = config.get('service.baseURL') + +/** + * host-meta endpoint + * @type {import('express').RequestParamHandler} + */ +export const xmlMeta = async (_req, res) => { + return res.set('Content-Type', 'text/xml') + .send(` + + + `) +} + +/** + * host-meta endpoint + * @type {import('express').RequestParamHandler} + */ +export const jsonMeta = async (_req, res) => { + return res.json({ + 'links': [ + { + 'rel': 'lrdd', + 'template': `${baseURL}/.well-known/webfinger?resource={uri}` + } + ] + }) +} -- cgit v1.2.3