Doing res.end in getServerSideProps hangs http clients like curl, axios, http etc.
See original GitHub issueWhat version of Next.js are you using?
12
What version of Node.js are you using?
16
What browser are you using?
Node (Backend issue)
What operating system are you using?
Windows
How are you deploying your application?
Vercel
Describe the Bug
THIS ONLY HAPPENS IN DEV MODE
While doing a res.end
in getServerSideProps returns correct data to the browser it doesn’t work with http clients like curl
Example
- Do a res.end in your getServerSideProps code and the run via ‘yarn dev’
export const getServerSideProps = ({res})=>{
res.setHeader("Content-Type", "text/plain")
res.write("Hello")
res.end()
return { props: {} }
}
- Try calling this page endpoint via curl eg:
curl http://localhost:3000/test-page
(Or try via axios via node script) Result: curl/axios just hangs indefinitely trying to fetch this request which doing the same in browser (or axios in a browser) works fine
Expected Behavior
If the response has ended then any http compliant client should be able to resolve the result. But seems the NextJs router doesn’t finish the request for non-browser clients.
To Reproduce
Described in the Bug descr.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why are cookies not sent to the server via getServerSideProps ...
This means you need to explicitly pass the cookies to the axios request to send them through. export async function getServerSideProps({ req }) ......
Read more >axios clear cookies | The AI Search Engine You Control
When i try to connect the backend server with http://domain:port. I can use Cors successful. Any http request will carry the cookies(sessionid, etc) ......
Read more >Web Design Manchester on Tumblr
Local website design and development company for Manchester businesses.
Read more >Syntax - Tasty Web Development Treats - Podcast Addict
Full Stack Developers Wes Bos and Scott Tolinski dive deep into web development topics, explaining how they work and talking about their own...
Read more >Fullstack React with TypeScript - Library
Patterns in React TypeScript Applications: Making Music with React . ... If you'd like to get help, help others, and hang out with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Non-React pages are better suited to be served from the
/public
folder in my opinion. You can generate them at build-time with a script for example.If that’s not an option/you have more dynamic data, I might suggest creating an API route instead and using a single
rewrites
rule to clean up the URL. https://nextjs.org/docs/api-reference/next.config.js/rewritesIn any case, I think we should fix the use of
res.end()
ingetServerSideProps()
, so thank you for reporting.This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.