How to avoid fetching from localhost #12763
-
My teammates and I are currently working on creating an example using Next.js with MongoDB. We basically finish it. It's running successfully on localhost. However, 500 Internal Server Error shows up when I try to deploy it on Zeit. It has to do with fetching data from localhost. Since we are new to all of these things, we are not sure on how to fix it. Can someone please take a look at our example? One possible solution is to put the db connection into getStaticProps directly and get the data from there directly. We are confused on how to do that. HELP WANTED. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The issue is in this line, it is making a request directly to Instead of making a request in
|
Beta Was this translation helpful? Give feedback.
The issue is in this line, it is making a request directly to
localhost:3000
, this isn't the port the app will be listening in production.Instead of making a request in
getInitialProps
for the/api/pets
endpoint, you can:getServerSideProps
(orgetStaticProps
) too, removing the need for a API call