fix(router): NIP-11 being served only on root instead of relay path#399
fix(router): NIP-11 being served only on root instead of relay path#399sagar-h007 wants to merge 4 commits intocameri:mainfrom
Conversation
| const settings = createSettings() | ||
|
|
||
| if (request.header('accept') === 'application/nostr+json') { | ||
| if (request.header('accept')?.includes('application/nostr+json')) { |
There was a problem hiding this comment.
Can you elaborate a bit why we can't use a strict equality check here?
There was a problem hiding this comment.
@cameri The Accept header isn’t always a single value, it often contains multiple types (sometimes with q-values), like:
application/nostr+json, application/json;q=0.9, /;q=0.8
With a strict equality check, this would fail even though the client clearly supports application/nostr+json.
Using .includes() avoids that issue and works better with how content negotiation is actually used in practice.
There was a problem hiding this comment.
@theAnuragMishra I was offline/sleeping , so let’s not pretend this was some real-time back-and-forth.
If you have a technical concern, point it out clearly and we can discuss it. Random shots about “AI hacks” don’t really help move the PR forward.
If something in the approach is wrong, explain what and why. Otherwise this just adds noise instead of anything useful.
There was a problem hiding this comment.
@sagar-h007 Do not engage with him.
Let's stay focused.
Can you check if the accepts package is installed and available? If so it's better to use it to check if a type is present in the accept header. The existing check and yours are still both naive because a value of q=0 would mean anything but that.
If the accepts package is not installed we might need to add it as a production dependency. If express is available, I think it's already included.
There was a problem hiding this comment.
Good catch,The current check is still naive and ignores q-values (like q=0). I’ll switch to using accepts for proper content negotiation, assuming it’s already available via Express. If not, I’ll add it.
|
Do you mind rebasing your PR on top of the main branch? |
3b9df8f to
fc75e61
Compare
|
@sagar-h007 Please fix the linting issues. |
Description
This PR fixes an issue where the NIP-11 relay information document was only being served at the root (
/) of the domain, even when the relay itself was configured on a different path (for example/v1).Specifically, this PR introduces the following changes:
Accept: application/nostr+json.includesinstead of strict equality).Related Issue
#381
Motivation and Context
According to the NIP-11 spec, the relay metadata should be available on the same URI that handles the WebSocket connection. In practice, this means a relay at
wss://domain.com/v1should expose its NIP-11 document athttps://domain.com/v1, not just athttps://domain.com/.Previously, WebSocket upgrades in Nostream were effectively path-agnostic, while Express routes were explicitly bound to
/. As a result, requests likeGET /v1withAccept: application/nostr+jsonreturned a404instead of the expected NIP-11 response. This change keeps the fix minimal while aligning behavior more closely with the NIP-11 spec and how relays are typically exposed behind proxies or path prefixes.How Has This Been Tested?
Tested locally by verifying that NIP-11 is now correctly served on the relay path (e.g.,
/v1). Verified that the existing behavior on the root (/) remains unchanged and that the updated handler successfully processes requests from real-world clients sending compound Accept headers.Test run:
curl -H "Accept: application/nostr+json" http://localhost:8008/v1Types of changes
Checklist: