简体   繁体   English

在Azure中为SVG和字体表达NodeJS web.config

[英]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. 我在Express网站上遇到了问题,该网站使用SVG和其他文件,如字体。

Did not have any problem when running app locally, but once deployed on Azure, SVG and fonts didn't appear anymore. 在本地运行应用程序时没有任何问题,但一旦部署在Azure上,SVG和字体就不再出现了。

Created a web.config file at project root: 在项目根目录创建了一个web.config文件:

<?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 ) 也用这个解决方案:( 在windows azure中的Svgs和其他mime类型

Both solutions now permit to load SVG files, but webpages are not loaded anymore. 这两种解决方案现在都允许加载SVG文件,但不再加载网页。 (HTTP 500) (HTTP 500)

It seems it overrides configuration for Dynamic Content . 它似乎覆盖了动态内容的配置。

How should Dynamic Content be configured to make app work again? 如何配置动态内容以使应用程序再次运行?

I found the problem. 我发现了这个问题。

Used this solution: ( Svgs and other mime types in windows azure ) 使用此解决方案:( Windows中的Svgs和其他mime类型

And in Dynamic Content Rewrite Rule , replaced server.js by app.js , which is the default entry point created by Express. 动态内容重写规则中 ,由app.js替换server.js ,这是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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM