fetch function pops up CORS error
Unanswered
Thrianta posted this in #help-forum
ThriantaOP
Below method is written in a client component that gives CORS error . Please help.
However below method works with server actions.
.................................
.............................................
....................................
On the other hand backend api has below headers
However below method works with server actions.
"use client".................................
.............................................
....................................
const res = await fetch(${process.env.NEXT_PUBLIC_APIURL}/api/blog, {
method: 'POST',
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization":Bearer ${session.token}},
body: JSON.stringify({
name,
image,
description,
})
})On the other hand backend api has below headers
response.setHeader('vary', 'Origin')
response.setHeader('Access-Control-Allow-Headers', 'content-type')
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'OPTIONS, POST');1 Reply
ThriantaOP
What I understood, api call will be blocked from a client component! Am I right?