Repository navigation
Fix the /api proxy: auth header, query string, all methods, gzip - #5
Merged
Merged
Conversation
The Next.js proxy used when nginx is not in front (e.g. on Vercel) only passed content-type and only handled GET and POST. - Forward Authorization (every logged-in call was rejected) - Handle PUT, PATCH, DELETE and HEAD (profile save and status changes returned 405) - Keep the query string and percent-encoding of the path - Drop content-encoding/content-length from the response: fetch has already decoded the body, so gzip responses arrived corrupted - Cancel the upstream request when the client disconnects - Do not pass cookies to the API; never cache; return JSON 502/503 when the API is unreachable or API_URL is unset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the Next.js
/api/*proxy (frontend/src/app/api/[...path]/route.ts). It is only used when nginx is not in front of the frontend, e.g. on Vercel; docker compose is unaffected.What was broken
Authorizationheader not forwardedcontent-encodingpassed through afterfetchhad decoded the body%2Fin an id became an extra path segmentWhat changed
authorization,content-type,accept,accept-language,last-event-id. Cookies andhostare not passed on.content-encoding,content-length,transfer-encoding,connectionandkeep-alivefrom the response.request.signalupstream and setscache: "no-store".{"detail": ...}with 502 when the API is unreachable and 503 whenAPI_URLis unset.Testing
Ran the production build (
.next/standalone/server.js) against a local fake backend that echoes what it receives. 21 checks: headers, each method with a body, bodiless POST, a 3 MB multipart upload, query string, encoded path, gzip, 404 pass-through,Content-Disposition, SSE arriving incrementally, and upstream cancellation on client disconnect.Not tested against the real API or on Vercel.
Notes
maxDurationis set, so Vercel's plan default applies. An apply session with review can run past five minutes and may need it raised.API_URL(the backend's address) is required by this route and is not yet documented in the README or.env.example.