How can I host a web.config-only server?

2019-07-29 13:23发布

Context

See this question: Enable CORS on Azure Service Bus Namespace

Really I want to have a front-end only ReactJS app that talks to the Azure API, and renders bits of the result onto the screen. Then gets input from the users and sends that back to the Azure API. Rinse and repeat. Unfortunately CORS pretty much rules that out, and you can't[1] override the CORS rules for a ServiceBus Namespace.

So the proposed solution is a thin proxy server, proxying the Azure API, to circumvent CORS.

(Alternative solutions to this question are HIGHLY welcome!)

[1] read: I can't currently see any way to, and nor can my Google Searches.

Question

The user on that other question proposes the relevant web.config file, so now I want to create that proxy server. I don't really want that server doing anything else, I want it to be as transparent as possible.

What is the simplest possible way to set up that server?


I'm kinda hoping that I would be able to do something like: "Tell Azure that I want a webserver, and paste/upload that web.config text into the Azure Portal"?

If it's relevant, currently my stack has literally nothing other than npm and the JS Create-React-App template's stack. I'm imagining we'll host the site in Azure too.

1条回答
淡お忘
2楼-- · 2019-07-29 13:40

I got this to work, and it was pretty painless - Azure can JustDoThis.

Documenting the notes I wrote for myself here, for any future lost wanderers :)


As noted in the linked question, the Azure server doesn't (and can't) enable CORS, so we need to circumvent that in some manner. The approach is to create a ReverseProxy server, which accepts the request, forwards it to Azure, receives the response, adds the relevant CORS headers and and returns it to the caller.

Followed steps, except skip the "Basic Authentication" step (Steps #3 & #4), from this Microsoft blog: https://blogs.msdn.microsoft.com/mihansen/2018/04/18/reverse-proxy-with-basic-authentication-in-azure-web-app/

  • Step 1: Create a new Azure Web App
  • Step 2: Add applicationHost.xdt file (in \Home\site)
  • Step 2a: Set the contents of the .xdt file using provided template (I think it's literally a web.config file?
<?xml version="1.0"?>  
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
<system.webServer>  
    <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />  
    </system.webServer>  
</configuration>
  • SKIP STEPS 3 & 4 (relate to Authentication which isn't necessary if it's just a redirect.)
  • Step 5: Update/Modify/Create rewrite rules

Step 2 is achieved through KUDU, which is accessible here:

https://yourazuresitedomain.scm.azurewebsites.net/

Some links about what KUDU is and how to use it:

查看更多
登录 后发表回答