Is it possible to enable CORS using NancyFX?

前端 未结 3 1557
日久生厌
日久生厌 2020-12-23 09:55

I have an API service made with NancyFX, and a couple of front-end developers creating an SPA JS client against this API.

We would like to test the client side code

3条回答
  •  温柔的废话
    2020-12-23 10:40

    Its possible to do this in the bootstraper of Nancy

    protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
    
           //CORS Enable
            pipelines.AfterRequest.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");
    
            });
    

提交回复
热议问题