Brrrrr
Brrrrr2w ago

Cors No 'Access-Control-Allow-Origin'

Hi, im working on a tcg project with oak and deno, but im getting this message: "Access to fetch at 'http://localhost:8000/users/6/cards' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource." Here is how im handling the fetch
const response = await fetch(`http://localhost:8000/users/${userId}/cards`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
mode: "cors",
body: JSON.stringify(requestBody),
});
const response = await fetch(`http://localhost:8000/users/${userId}/cards`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
mode: "cors",
body: JSON.stringify(requestBody),
});
and here is what i have on my server.ts
app.use(
oakCors({
origin: ['http://localhost:5173'],
allowedHeaders: ['Content-Type', 'Authorization'],
methods: ['GET', 'POST', 'OPTIONS'],
credentials: true,
})
);
app.use(
oakCors({
origin: ['http://localhost:5173'],
allowedHeaders: ['Content-Type', 'Authorization'],
methods: ['GET', 'POST', 'OPTIONS'],
credentials: true,
})
);
Any advice would be appreciated
4 Replies
lcasdev
lcasdev2w ago
Is that app.use right at the start, before you register anything else with the app?
Brrrrr
BrrrrrOP2w ago
yes it is tried * aswell, didnt work
lcasdev
lcasdev2w ago
Without more details about the project I can’t really offer any other help
Brrrrr
BrrrrrOP2w ago
nvm i fixed it had something to do with the jwt token :deno_thumbs_up:

Did you find this page helpful?