Slug Api Fetch error
I have a backend running on:
http://test.localhost/api/housing/db-apartments/26e87de6-f912-49de-86e8-407fb3ca997e
Which returns data for a single item.
In my nextjs frontend which runs on http://localhost:3000
I have a
[slug].tsx
which does following:
The generated url is correct, but I get this error
The dev console says:
What am I missing, shouldn't it just fetch the data?3 Replies
Main thing I’m noticing is the subdomain on localhost (not common, so idk if that’s related), but the port is missing from the API url you’ve pasted. From what I’ve searched up, even with the subdomain on local host, you still need the port that backend is running on.
test.localhost:<port number>/api/*
try adding that in and seeing if it solves it!Its runs on port 80 thats why I did not need that, its a subdomain because there is a multitenant backend with different subdomains running.
I'll try:
test.localhost:80/api/*
But aside from that it should work you say?
From what I can tell, yes. Next step might be checking the appropriate service to ensure it’s receiving the request. If it isn’t, then there may be an issue with local DNS resolving the uri
You can also check the network tab of your browser for this info (request should go out but fail) and it should give better info like request headers, response headers, etc. scratch this forgot we were working with an SSR component
Also, I’m noticing you’re using a rewrite, would you be able to share that rewrite from your next config? It could possibly be related to that vs the local DNS