1

can someone please explain how to use the next API in the production server? on my local works all fine but when deploying to vercel, got this error:

FetchError: request to http://localhost:3000/api/notes failed, reason: connect ECONNREFUSED 127.0.0.1:3000

makes sense that I don't have full access to their servers and ports... but I tried in my app to only const res = await fetch('/api/notes'); but got a TypeError: Only absolute URLs are supported

so I should use my static DNS for this? but it will be much easier, faster to pull data from localhost rather than go up to the internet and after come back with the data on the server... don't get it

enkicoma
  • 461
  • 4
  • 25
  • 1
    https://stackoverflow.com/questions/44342226/next-js-error-only-absolute-urls-are-supported does this answer your question? – timbersaw Mar 01 '21 at 12:55
  • half of it, thx - https://stackoverflow.com/a/44344023/8780756 But still, this will go up to the internet DNS /api/path and after come back to the server. Still, don't get why won't use local server URL. – enkicoma Mar 01 '21 at 18:26

1 Answers1

1

You need to add the path for the server you join to deploy. Example:

const res = await fetch('https://mynextapp.vercel.app/api/notes');
Armany
  • 19
  • 3
  • 2
    Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 06 '21 at 07:27