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

女生的网名这么多〃 提交于 2019-12-11 07:33:32

问题


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:


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:

  • https://blogs.msdn.microsoft.com/benjaminperkins/2014/03/24/using-kudu-with-windows-azure-web-sites/
  • https://www.jamessturtevant.com/posts/How-to-add-edit-and-remove-files-in-your-azure-webapp-using-the-kudu-service-dashboard/


来源:https://stackoverflow.com/questions/51024724/how-can-i-host-a-web-config-only-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!