diff options
author | Vitaly Takmazov | 2024-10-22 08:50:02 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2024-10-22 08:50:02 +0300 |
commit | 7e6601867f08b31cc3ee4373ec748ac1aba2f6cf (patch) | |
tree | 8a182ec29e560a5dcdf2afe0c223a9112773f66e /vnext/server | |
parent | 1386cbcb9e84c37cc5d6164028499e60219c439c (diff) |
vnext: RFC 6415: Web Host Metadata
Diffstat (limited to 'vnext/server')
-rw-r--r-- | vnext/server/app.js | 6 | ||||
-rw-r--r-- | vnext/server/middleware/host-meta.js | 30 |
2 files changed, 36 insertions, 0 deletions
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(`<?xml version="1.0" encoding="UTF-8"?> + <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"> + <Link rel="lrdd" template="${baseURL}/.well-known/webfinger?resource={uri}"/> + </XRD>`) +} + +/** + * 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}` + } + ] + }) +} |