Next.js Discord

Discord Forum

HTTP not s Request:

Answered
Sun bear posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by Ray
you could create a route handler and fetch the http endpoint
/api/proxy?url=http://127.0.0.1:5000/result
View full answer

29 Replies

Avatar
Ray
yes, we can make a fetch request in nextjs.
I don't see any problem with the code above yet. could you show more code where do you use fetchRating?
Avatar
Sun bear
i cant use http in nextJS when hosted on vercel. It says it is not allowed
Avatar
Ray
oh do you mean you are trying to make http request on a site running on https?
Avatar
CollertJK
So, are you trying to fetch through localhost on production?
How is it possible
Avatar
Sun bear
I have the page hosted on vercel but the data I need is on a http server
Avatar
CollertJK
The issue may be that it can't reach your api if it's hosted on your local host and not on the the same
Avatar
Ray
we can't, because of Mixed Content Security Policy
https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content
where do you call fetchRating()? on page load?
Avatar
Sun bear
i do it when submiting data to the server
Avatar
Ray
you could create a route handler and fetch the http endpoint
/api/proxy?url=http://127.0.0.1:5000/result
Answer
Avatar
Ray
could you show the code?
Avatar
Sun bear
Image
Avatar
Ray
could you turn this to server action?
or create a route handler
it should be fine if the http request is made on the server side
Avatar
Sun bear
i put the whole fetch logic in a route once but it did not helped
Avatar
Ray
oh can I try to fetch the endpoint?
Avatar
Sun bear
server is currently offline
Avatar
Ray
nm Im trying to fetch another endpoint on http
Avatar
Sun bear
i am waiting for my partner to power it up
Avatar
Ray
let me deploy it to vercel
yes you can't make http request on a https site
Avatar
Sun bear
xD 🙂
Avatar
Ray
try fetch your api on server side
I can't find a http endpoint to test lol
the one I was trying redirect the request to https
or run your server on https
Avatar
Sun bear
thanks anyway 🙂