Getting Cors error on feature bracnhes
Unanswered
Smaller yellow ant posted this in #help-forum
Smaller yellow antOP
so we have next 14 in the company and it has 2 apis , everything i do with them for not getting cores error keeps getting the error, i tried middleware, next js config, api config, none of them could solve this cores issue, the issue is we cant add every feature branch we have to the list of allowed orgin so i tried using " * " none of them work , pls any one knows the solution?
const handleCORS = (req: NextRequest, res: NextResponse) => {
// Add CORS headers
res.headers.set("Access-Control-Allow-Origin", "*");
res.headers.set("Access-Control-Allow-Methods", "GET,DELETE,PATCH,POST,PUT");
res.headers.set(
"Access-Control-Allow-Headers",
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
);
// Handle preflight OPTIONS request
if (req.method === "OPTIONS") {
return new NextResponse(null, { status: 200 });
}
return res;
};4 Replies
@gin what doesnt work?
Smaller yellow antOP
i get cors error for calling apis, the url is like dev.somthing.com is the api that we use so this api gets cors error on featurebranch.app.run but works on the same domain
we have 2 apis in the next js application that is being devployed to dev, the feature branches that call the dev api get cors error, even tho i changed this , still causes cors error!