Next.js Discord

Discord Forum

cors error on custim nginx server

Unanswered
gref9730 posted this in #help-forum
Open in Discord
Avatar
hello I have all fetches created as this where im using "http:"

but im hosting the app on custom linux server where I have set up nginx which listens on port 80 and propagate it to the next js app which is running on "localhost:3000"

...nextConfig. it all worked before I created with certbot for the nginx a ssl certificate ... now im getting on all fetches CORS error and whe I tried to change in all fetches functions to

"https" ... and tried to rebuild the app im getting errors while building that the fetches cant reach target and that it doesnt exist... probably bcs the next js app is running on http

and the nginx is running on https ... but idk what to do now to make it work..

anyone can help?


asnyc function randomFetch(val: string){
const response = await fetch('http://${process.env.URL}/api/something',
{
cache: "no-store",
method: "POST",
body: JSON.stringify({something:val})
}
);
if(!response.ok){
throw new Error("Failed to fetch data..");
}
return response.json()

}

0 Replies