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
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
oh do you mean you are trying to make http request on a site running on https?
Avatar
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
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
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
you could create a route handler and fetch the http endpoint
/api/proxy?url=http://127.0.0.1:5000/result
Answer
Avatar
could you show the code?
Avatar
Sun bear
Image
Avatar
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
oh can I try to fetch the endpoint?
Avatar
Sun bear
server is currently offline
Avatar
nm Im trying to fetch another endpoint on http
Avatar
Sun bear
i am waiting for my partner to power it up
Avatar
let me deploy it to vercel
yes you can't make http request on a https site
Avatar
Sun bear
xD 🙂
Avatar
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 🙂