Skip to content

Commit 6dc69cb

Browse files
sagar-h007cameri
andauthored
fix(router): NIP-11 being served only on root instead of relay path (#399)
* fix(router): map NIP-11 to all WebSocket endpoints with flexible Accept matching * fix: use proper http content negotiation for nip-11 accept headers * fix: sort imports alphabetically in routes/index.ts --------- Co-authored-by: Ricardo Cabral <me@ricardocabral.io>
1 parent 3a691ef commit 6dc69cb

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/handlers/request-handlers/root-request-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NextFunction, Request, Response } from 'express'
2+
import accepts from 'accepts'
23
import { path } from 'ramda'
34

45
import { createSettings } from '../../factories/settings-factory'
@@ -9,7 +10,7 @@ import packageJson from '../../../package.json'
910
export const rootRequestHandler = (request: Request, response: Response, next: NextFunction) => {
1011
const settings = createSettings()
1112

12-
if (request.header('accept') === 'application/nostr+json') {
13+
if (accepts(request).type(['application/nostr+json'])) {
1314
const {
1415
info: { name, description, pubkey: rawPubkey, contact, relay_url },
1516
} = settings

src/routes/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import accepts from 'accepts'
12
import express from 'express'
23

34
import { nodeinfo21Handler, nodeinfoHandler } from '../handlers/request-handlers/nodeinfo-handler'
@@ -11,6 +12,13 @@ import { rootRequestHandler } from '../handlers/request-handlers/root-request-ha
1112

1213
const router = express.Router()
1314

15+
router.use((req, res, next) => {
16+
if (req.method === 'GET' && accepts(req).type(['application/nostr+json'])) {
17+
return rootRequestHandler(req, res, next)
18+
}
19+
next()
20+
})
21+
1422
router.get('/', rootRequestHandler)
1523
router.get('/healthz', getHealthRequestHandler)
1624
router.get('/terms', getTermsRequestHandler)

0 commit comments

Comments
 (0)