Skip to content

Commit

Permalink
feat: add nodeinfo support (#347)
Browse files Browse the repository at this point in the history
Thank you!
  • Loading branch information
alexgleason authored Jan 8, 2024
1 parent 9bf0262 commit d9e4020
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/handlers/request-handlers/nodeinfo-handler.ts
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 5 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)

Expand Down

0 comments on commit d9e4020

Please sign in to comment.