Back to blog
Article

CORS Errors and ways to Fix via NextJS/Vercel

What is CORS? Cross-Origin Resource Sharing ( CORS ) is a standard that allows a server to relax the same-origin policy . This is used to explicitly allow some cross-origin requests while rejecting others. From...

AorBorC field note / Last reviewed July 9, 2026

2m
Read time
Dec
Published
CORS Errors and ways to Fix via NextJS/Vercel

What is CORS?

Cross-Origin Resource Sharing (CORS) is a standard that allows a server to relax the same-origin policy. This is used to explicitly allow some cross-origin requests while rejecting others. 

From Mozilla https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors

Basically what it means is that, if you are on site aorborc.com and trying to request information from doreorf.com via client side javascript, the browser will through this error.

Sample Errors


The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.


It does not have HTTP ok status.


How to fix it

If you are a nextjs/vercel user like us, when you respond from your server, just add the below code inside your API function

export default async function handler(req, res) {
  res.setHeader("Access-Control-Allow-Credentials", true);
  res.setHeader(
    "Access-Control-Allow-Origin",
    req.headers.origin ? req.headers.origin : "*"
  );
  res.setHeader(
    "Access-Control-Allow-Methods",
    "GET,OPTIONS,PATCH,DELETE,POST,PUT"
  );
  res.setHeader(
    "Access-Control-Allow-Headers",
    "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
  );
  //For CORS
  if (req.method === "OPTIONS") {
    res.status(200).end();
    return;
  }
//Your rest of the code below
res.status(200).json({result:"Ok"});
}

The above code should avoid CORS error for your custom next js server.

Next step

Need help mapping this workflow?

Start with the workflow, roles, decisions, and system handoffs. AorBorC can map the operating problem, identify the right build path, and define a practical first phase before your team commits to implementation.

Related Articles

October 21, 2024

Zoho CRM API: Error Codes & Troubleshooting

Learn how to troubleshoot common Zoho CRM API errors, manage error codes, and implement best practices for seamless API integration.

Read article

April 18, 2024

5 Coding Mistakes Businesses Make (and How to Avoid Them)

In today's digital age, having a strong online presence is no longer a luxury - it's a necessity. Whether you're a seasoned entrepreneur or a fresh startup, a well-coded website or app can be the key to unlocking new...

Read article