From 524126119c37234c5da2584fe135c7174bfd41f9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 19 Dec 2023 13:14:45 -0600 Subject: [PATCH] feat: add nodeinfo support --- .../request-handlers/nodeinfo-handler.ts | 40 +++++++++++++++++++ src/routes/index.ts | 5 +++ 2 files changed, 45 insertions(+) create mode 100644 src/handlers/request-handlers/nodeinfo-handler.ts diff --git a/src/handlers/request-handlers/nodeinfo-handler.ts b/src/handlers/request-handlers/nodeinfo-handler.ts new file mode 100644 index 00000000..0a2ebf73 --- /dev/null +++ b/src/handlers/request-handlers/nodeinfo-handler.ts @@ -0,0 +1,40 @@ +import { NextFunction, Request, Response } from 'express' +import packageJson from '../../../package.json' + +export const nodeinfoHandler = (req: Request, res: Response, next: NextFunction) => { + res.json({ + links: [{ + rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', + href: `https://${req.hostname}/nodeinfo/2.0`, + }, { + rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1', + href: `https://${req.hostname}/nodeinfo/2.1`, + }], + }).send() + next() +} + +export const nodeinfo21Handler = (_req: Request, res: Response, next: NextFunction) => { + res.json({ + version: '2.1', + software: { + name: 'nostream', + version: packageJson.version, + repository: packageJson.repository.url, + homepage: packageJson.homepage, + }, + protocols: ['nostr'], + services: { + inbound: [], + outbound: [], + }, + openRegistrations: true, + usage: { + users: {}, + }, + metadata: { + features: ['nostr_relay'], + }, + }).send() + next() +} \ No newline at end of file diff --git a/src/routes/index.ts b/src/routes/index.ts index 2c1e963f..04d288e2 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,5 +1,6 @@ import express from 'express' +import { nodeinfo21Handler, nodeinfoHandler } from '../handlers/request-handlers/nodeinfo-handler' import callbacksRouter from './callbacks' import { getHealthRequestHandler } from '../handlers/request-handlers/get-health-request-handler' import { getTermsRequestHandler } from '../handlers/request-handlers/get-terms-request-handler' @@ -13,6 +14,10 @@ router.get('/', rootRequestHandler) router.get('/healthz', getHealthRequestHandler) router.get('/terms', getTermsRequestHandler) +router.get('/.well-known/nodeinfo', nodeinfoHandler) +router.get('/nodeinfo/2.1', nodeinfo21Handler) +router.get('/nodeinfo/2.0', nodeinfo21Handler) + router.use('/invoices', rateLimiterMiddleware, invoiceRouter) router.use('/callbacks', rateLimiterMiddleware, callbacksRouter)