Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Fix: Add support for res.redirect in API routes #93

Merged
merged 1 commit into from
Nov 18, 2020

Conversation

FinnWoelm
Copy link
Contributor

⚠️ MERGE THIS PR AFTER #92 ⚠️

This PR adds support for res.redirect in API routes as described in https://nextjs.org/docs/api-routes/response-helpers

It does this by returning the res object from res.writeHead, thus allowing method chaining. This is how a ServerResponse object should behave according to https://nodejs.org/api/http.html#http_response_writehead_statuscode_statusmessage_headers. The other mock methods of the res object probably need to be adjusted in the future, too.

This PR resolves #74 (thanks for the test case, @afzalsayed96! It's the first commit in this PR 🙂 ).

@lindsaylevine lindsaylevine added the type: bug code to address defects in shipped code label Nov 18, 2020
Copy over the files from the next-aws-lambda package and manually
bundle them into our Netlify Functions. This gives us more flexibility
to customize the compatibility layer between Netlify Functions and
Next.js. For now, no changes have been made to the next-aws-lambda
files and they have been copied as-is.

next-aws-lambda source: https://github.com/serverless-nextjs/serverless-next.js/tree/master/packages/compat-layers/apigw-lambda-compat
@lindsaylevine lindsaylevine force-pushed the fix-api-route-redirects branch from c9c99fb to a093007 Compare November 18, 2020 10:39
@lindsaylevine lindsaylevine merged commit ee478cf into main Nov 18, 2020
lindsaylevine added a commit that referenced this pull request Nov 18, 2020
- Fix: don't empty publish/function paths unless they're default ([#94](#94))
- Fix: add support for res.redirect in API routes ([#93](#93))
- Remove next-aws-lambda dependency (now inlined) ([#92](#92))
- Fix: Node.js version in CI ([#91](#91))
@FinnWoelm FinnWoelm deleted the fix-api-route-redirects branch November 20, 2020 02:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants