DenoDDeno
Powered by
BrrrrrB
Denoβ€’10mo agoβ€’
6 replies
Brrrrr

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
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Access to script at 'node:buffer' from origin "...localhost..." has been blocked by CORS policy
SyrupThinkerSSyrupThinker / help
3y ago
cors header issue
andrewAandrew / help
16mo ago
Deno deploy --allow-write permission.
PonchoPPoncho / help
3y ago