CORS Issue on only some API calls
I have multiple API calls on my project deployed to vercel but only some of them face CORS issues, for example:
works perfectly fine however
doesn't work when visiting the production URL despite the first one working. I get this error:
Access to XMLHttpRequest at 'http://localhost:3000/api/fetchtopicid?name=electricity' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Solution:Jump to solution
```ts
//You can do it like this.
export async function GET(request: Request) {
return new Response('Hello, Next.js!', {...
10 Replies
U can try with "Access-Control-Allow-Origin": "*" to see if its working
didn't work sadly, what confuses me is that the api call withou any CORS configuration works but the second one doesn't work
did you try it without cors headers?
yeah, still didn't work
you probably need a cors middleware then.
if you make const headers variable will that automaticly append it to the headers?
Stack Overflow
NextJs CORS issue
I have a Next.js app hosted on Vercel at www.example.com, which needs to communicate with a backend .NET Core Web API hosted on a different server at api.example.com.
The .NET core web api has been
check the first answer.
GitHub
How to enable cors in Nextjs 13 Route Handlers · vercel next.js · D...
Summary Hi all I would like to define CORS to allow any origin for development purposes with Nextjs 13 route handlers. I tried the following options, but they did not work: In the route handler its...
Solution
this worked 🙏, tysm