feat: add nodeinfo support (#347)

Thank you!
This commit is contained in:
Alex Gleason 2024-01-08 11:37:59 -06:00 committed by GitHub
parent 9bf0262cfc
commit d9e402060d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -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()
}

View File

@ -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)