`/_openapi.json` lists an `http://` "Local Development Server" in production

Aperta
#5,180 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript
Ambito
api, backend

Direzione di ricerca

Start in src/runtime/internal/routes/openapi.ts, where the server URL comes from getRequestURL(event).origin, and compare it with how the dev error page passes forwarded-header options. Run the linked repro with forwarded headers to confirm the http:// URL and the dev label. Done when /_openapi.json returns the https origin behind a proxy and omits the dev description in production. Whether to trust x-forwarded-host is a maintainer decision, so check with them first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Behind a proxy that terminates TLS, /_openapi.json in a production build lists the server as plain http:// and calls it "Local Development Server".

curl -s -H 'x-forwarded-proto: https' -H 'x-forwarded-host: example.com' \
  http://127.0.0.1:3917/_openapi.json | jq .servers
# [{ "url": "http://127.0.0.1:3917", "description": "Local Development Server", "variables": {} }]

I expected https://example.com and no dev label. Repro, built with pnpm install && pnpm build and started with PORT=3917 node .output/server/index.mjs:
https://github.com/onmax/repros/tree/repro/nitro-openapi-servers/nitro-openapi-servers

Nitro 3.0.261103-rc and main at 8b54a5f3, h3 2.0.8, node-server preset, openAPI: { production: "runtime" }, Node 24.21.0, Linux.

openapi.ts uses getRequestURL(event).origin, and h3 v2 ignores forwarded headers unless you ask for them. h3 v1 trusted x-forwarded-proto, so nitropack 2.14 returns https:// for the same request, which the repro checks too. The description is hardcoded, and there's no option to set servers.

I have a fix on a branch. It passes { xForwardedHost: true, xForwardedProto: true } like the dev error page does, and sets the description only in dev. The test fails on main.
https://github.com/nitrojs/nitro/compare/main...onmax:nitro:fix/openapi-forwarded-server-url

If you'd rather not trust x-forwarded-host, xForwardedProto alone gets back the Nitro 2 behaviour. A servers option in openAPI would work too. I can open a PR if you want it.

Lingua principale
TypeScript
Stelle
11.5k
Fork
968
Merge medio
4g 9h
PR unite (30g)
64

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nitrojs/nitro

Tutte le issue di nitrojs/nitro

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.