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

Commit c9c99fb

Browse files
committed
Add support for res.redirect in API routes
Return the res object from writeHead, so that other methods (like end()) can be chained. We may need to adjust other methods on our res object as well to match the http ServerResponse that Next.js expects.
1 parent 6239191 commit c9c99fb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/templates/createResponseObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const createResponseObject = ({ onResEnd }) => {
2424
res.writeHead = (status, headers) => {
2525
response.statusCode = status;
2626
if (headers) res.headers = Object.assign(res.headers, headers);
27+
28+
// Return res object to allow for chaining
29+
// Fixes: https://github.com/netlify/next-on-netlify/pull/74
30+
return res;
2731
};
2832
res.write = (chunk) => {
2933
if (!response.body) {

0 commit comments

Comments
 (0)