Is it possible to enable CORS using NancyFX

0 votes
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 against the published server without having to publish the client code with too much frequency.

But, the client runs at localhost, and the server is at Windows Azure.

Is it possible and easy to enable CORS on the NancyFX server? How can I do that?

Thanks.
Aug 24, 2018 in Azure by cloudie_crank
• 1,610 points
2,219 views

1 answer to this question.

0 votes

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");

        });
answered Aug 24, 2018 by null_void
• 3,220 points

Related Questions In Azure

0 votes
1 answer
0 votes
1 answer

Is it possible to access performance counter in Microsoft Azure Web App?

No, it is not supported on Azure ...READ MORE

answered Jul 4, 2019 in Azure by Perry
• 17,100 points
1,005 views
0 votes
1 answer

Is it possible to pass parameters to a pipeline run?

Yes, parameters are a first-class, top-level concept ...READ MORE

answered Jan 2, 2020 in Azure by Sirajul
• 59,230 points
2,272 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Is there a way to get ERROR details on Azure website?

You have two options: First, you can turn ...READ MORE

answered May 25, 2018 in Azure by club_seesharp
• 3,450 points
2,632 views
0 votes
1 answer

Is it possible to write to file system on Azure Website?

Yes you can. It is possible to ...READ MORE

answered Jun 27, 2018 in Azure by null_void
• 3,220 points
1,547 views
+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
2,208 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP