Skip to content

Commit d9e4020

Browse files
authored
feat: add nodeinfo support (#347)
Thank you!
1 parent 9bf0262 commit d9e4020

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { NextFunction, Request, Response } from 'express'
2+
import packageJson from '../../../package.json'
3+
4+
export const nodeinfoHandler = (req: Request, res: Response, next: NextFunction) => {
5+
res.json({
6+
links: [{
7+
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
8+
href: `https://${req.hostname}/nodeinfo/2.0`,
9+
}, {
10+
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
11+
href: `https://${req.hostname}/nodeinfo/2.1`,
12+
}],
13+
}).send()
14+
next()
15+
}
16+
17+
export const nodeinfo21Handler = (_req: Request, res: Response, next: NextFunction) => {
18+
res.json({
19+
version: '2.1',
20+
software: {
21+
name: 'nostream',
22+
version: packageJson.version,
23+
repository: packageJson.repository.url,
24+
homepage: packageJson.homepage,
25+
},
26+
protocols: ['nostr'],
27+
services: {
28+
inbound: [],
29+
outbound: [],
30+
},
31+
openRegistrations: true,
32+
usage: {
33+
users: {},
34+
},
35+
metadata: {
36+
features: ['nostr_relay'],
37+
},
38+
}).send()
39+
next()
40+
}

src/routes/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express from 'express'
22

3+
import { nodeinfo21Handler, nodeinfoHandler } from '../handlers/request-handlers/nodeinfo-handler'
34
import callbacksRouter from './callbacks'
45
import { getHealthRequestHandler } from '../handlers/request-handlers/get-health-request-handler'
56
import { getTermsRequestHandler } from '../handlers/request-handlers/get-terms-request-handler'
@@ -13,6 +14,10 @@ router.get('/', rootRequestHandler)
1314
router.get('/healthz', getHealthRequestHandler)
1415
router.get('/terms', getTermsRequestHandler)
1516

17+
router.get('/.well-known/nodeinfo', nodeinfoHandler)
18+
router.get('/nodeinfo/2.1', nodeinfo21Handler)
19+
router.get('/nodeinfo/2.0', nodeinfo21Handler)
20+
1621
router.use('/invoices', rateLimiterMiddleware, invoiceRouter)
1722
router.use('/callbacks', rateLimiterMiddleware, callbacksRouter)
1823

0 commit comments

Comments
 (0)