locked
Serving static content on azure RRS feed

  • Question

  • I have react project that I have deployed on Azure, the problem is I dont get the static files served. This is not my project, it is by UI designer and I am not much of a front end guy familiar in node stuffs. 

    I tried editing web.config as following and I am also sharing the folder structure. I am just trying to know if it is must to use CDN to serve these static files? Or can I write server.js file to serve these files? Or do I need to edit my web.config file properly?

    I would appreciate any helpful answer.

    web.config:

    <?xml version="1.0"?>
    <configuration>
     <system.webServer>
     <rewrite>
        <rules>
            <rule name="React Routes" stopProcessing="true">
                <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <!-- <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> -->
                    </conditions>
                    <action type="Rewrite" url="/" />
            </rule>
             <!-- <rule name="Express.js URIs">
                <match url="api/*" />
                <action type="Rewrite" url="server.js" />
            </rule> -->
            <rule name="Static files" stopProcessing="true">
                <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_URI}" pattern="assets\/*" ignoreCase="true" />
                    </conditions>
                <action type="Redirect" url="/"/>
            </rule> 
            <!-- <rule name="Static Files" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{APPL_PHYSICAL_PATH}wwwroot\{R:1}" matchType="IsFile" />
                </conditions>
                <action type="Rewrite" url="/{R:1}" />
            </rule> -->
        </rules>
     </rewrite>
     </system.webServer>
    </configuration>

    folder structure:


    Monday, November 20, 2017 1:53 AM

All replies

  • Can you share the URL, so I can better understand whats wrong? What do you mean when you say you "don't get the static files served"?

    Are your serving your HTML file from the CDN or from the origin?

    In order to serve from the CDN, you may need to change the static URL's to use the CDN endpoint instead. See here for more details: https://docs.microsoft.com/en-us/azure/cdn/cdn-cloud-service-with-cdn 

    This isn't something that you can do just in web.config. Most people prefer to serve static content via CDN for performance reasons, but no its not something that you HAVE to do.

    Tuesday, November 21, 2017 12:01 AM