Skip to content

Commit fc75e61

Browse files
committed
fix: use proper http content negotiation for nip-11 accept headers
1 parent 0d84d62 commit fc75e61

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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')?.includes('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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import express from 'express'
2+
import accepts from 'accepts'
23

34
import { nodeinfo21Handler, nodeinfoHandler } from '../handlers/request-handlers/nodeinfo-handler'
45
import admissionRouter from './admissions'
@@ -12,7 +13,7 @@ import { rootRequestHandler } from '../handlers/request-handlers/root-request-ha
1213
const router = express.Router()
1314

1415
router.use((req, res, next) => {
15-
if (req.method === 'GET' && req.headers.accept?.includes('application/nostr+json')) {
16+
if (req.method === 'GET' && accepts(req).type(['application/nostr+json'])) {
1617
return rootRequestHandler(req, res, next)
1718
}
1819
next()

0 commit comments

Comments
 (0)