HTTP not s Request:
Answered
Sun bear posted this in #help-forum
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
29 Replies
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
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
I don't see any problem with the code above yet. could you show more code where do you use
fetchRating
?![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
i cant use http in nextJS when hosted on vercel. It says it is not allowed
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
oh do you mean you are trying to make http request on a site running on https?
![Avatar](https://cdn.discordapp.com/avatars/366684552040808458/57574d5d236bb2be9063a877d8f9cad8.webp?size=256)
CollertJK
So, are you trying to fetch through localhost on production?
How is it possible
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
I have the page hosted on vercel but the data I need is on a http server
![Avatar](https://cdn.discordapp.com/avatars/366684552040808458/57574d5d236bb2be9063a877d8f9cad8.webp?size=256)
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](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
we can't, because of Mixed Content Security Policy
https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content
https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content
where do you call
fetchRating()
? on page load?![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
i do it when submiting data to the server
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
you could create a route handler and fetch the http endpoint
/api/proxy?url=http://127.0.0.1:5000/result
Answer
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
could you show the code?
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
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](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
i put the whole fetch logic in a route once but it did not helped
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
oh can I try to fetch the endpoint?
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
server is currently offline
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
nm Im trying to fetch another endpoint on http
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
i am waiting for my partner to power it up
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
let me deploy it to vercel
yes you can't make http request on a https site
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
xD 🙂
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
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](https://cdn.discordapp.com/embed/avatars/2.png)
Sun bear
thanks anyway 🙂