Brrrrr
Brrrrr
DDeno
Created by Brrrrr on 5/21/2025 in #help
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
7 replies