question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doing res.end in getServerSideProps hangs http clients like curl, axios, http etc.

See original GitHub issue

What 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

  1. 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: {} }

}
  1. 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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Jan 4, 2022

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/rewrites

In any case, I think we should fix the use of res.end() in getServerSideProps(), so thank you for reporting.

0reactions
balazsorban44commented, Feb 16, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found