Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express NodeJS web.config in Azure for SVG & Fonts

I had a problem in an Express website, which uses SVG and other files like fonts.

Did not have any problem when running app locally, but once deployed on Azure, SVG and fonts didn't appear anymore.

Created a web.config file at project root:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <system.webServer>

      <staticContent>
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
        <mimeMap fileExtension=".ttf" mimeType="application/x-woff" />
      </staticContent>

    </system.webServer>
  </configuration>

Also used this solution: (Svgs and other mime types in windows azure)

Both solutions now permit to load SVG files, but webpages are not loaded anymore. (HTTP 500)

It seems it overrides configuration for Dynamic Content.

How should Dynamic Content be configured to make app work again?

like image 236
kube Avatar asked Jan 15 '23 05:01

kube


1 Answers

I found the problem.

Used this solution: (Svgs and other mime types in windows azure)

And in Dynamic Content Rewrite Rule, replaced server.js by app.js, which is the default entry point created by Express.

Final result is:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <system.webServer>

      <staticContent>
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
        <mimeMap fileExtension=".ttf" mimeType="application/x-woff" />
      </staticContent>

      <handlers>
        <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
      </handlers>

      <rewrite>
        <rules>
          <rule name="DynamicContent">
            <match url="/*" />
            <action type="Rewrite" url="app.js" />
          </rule>
        </rules>
      </rewrite>

    </system.webServer>
  </configuration>
like image 54
kube Avatar answered Jan 21 '23 05:01

kube