Deno Oak Disable Cors

前端 未结 4 753
陌清茗
陌清茗 2021-01-15 11:40

I am trying to \'connect\' my small React JS app with my Deno API backend on my local environment with fetch().

   con         


        
相关标签:
4条回答
  • 2021-01-15 11:57

    placeapp.use(oakCors()) before your routes like this:

    app.use(oakCors())
    app.use(route.routes())
    

    this is allow all CORS before to manage the routes

    0 讨论(0)
  • 2021-01-15 12:14

    This works just fine:

    app.use(oakCors({ origin: "*" }));
    
    0 讨论(0)
  • 2021-01-15 12:18

    For me, I had to first pass oakCors configuration to the app and then the routes.

    app.use(oakCors({
        origin: 'http://localhost:4200',
        optionsSuccessStatus: 200,
    }));
    app.use(router.routes());
    
    0 讨论(0)
  • 2021-01-15 12:20

    Solution in my case was pretty easy.

    I had to import oakCors into my Deno API app.ts

    import { oakCors } from "https://deno.land/x/cors/mod.ts";
    

    after that, just add the excluded origin after app instantiation:

    app.use(
        oakCors({
          origin: "http://localhost:3000"
        }),
    );
    

    NOTE: I tried to set origin to origin: false and that did not work in my case.

    For more options on Deno CORS here is a link: https://deno.land/x/cors

    0 讨论(0)
提交回复
热议问题