Getting CORS To Work With Nancy

后端 未结 3 1644
面向向阳花
面向向阳花 2021-01-11 14:53

I am trying to get all types of requests to work with Nancy and CORS. Currently I add a pipeline at the end of the request:

            pipelines.AfterReques         


        
3条回答
  •  有刺的猬
    2021-01-11 15:40

    I don't think you need to specify OPTIONS as an allowed CORS method. I've never seen that set, and I've never set it myself. Browsers don't complain.

    Otherside I have a similar setup as you in my :

    public abstract class MyModule : NancyModule
        protected MyModule(bool hasRazorView = true)
            After.AddItemToEndOfPipeline((ctx) => ctx.Response
                .WithHeader("Access-Control-Allow-Origin", "*")
                .WithHeader("Access-Control-Allow-Methods", "POST,GET")
                .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type"));
            . . . .
        }
    }
    

    In my case, the CORS get sent on my GET and POST, but not the OPTIONS. I overrode the default OPTIONS handling with Options["/"] = route => new Response(). That let the rest of the pipeline fire.

提交回复
热议问题