首页 文章

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

提问于
浏览
5

我在Express网站上遇到了问题,该网站使用SVG和其他文件,如字体 .

在本地运行应用程序时没有任何问题,但一旦部署在Azure上,SVG和字体就不再出现了 .

在项目根目录创建了一个 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>

也用这个解决方案:(Svgs and other mime types in windows azure

这两种解决方案现在都允许加载SVG文件,但不再加载网页 . (HTTP 500)

它似乎覆盖了 Dynamic Content 的配置 .

如何配置动态内容以使应用程序再次运行?

1 回答

  • 9

    我发现了这个问题 .

    使用此解决方案:(Svgs and other mime types in windows azure

    Dynamic Content Rewrite Rule 中,由 app.js 替换 server.js ,这是Express创建的默认入口点 .

    最终结果是:

    <?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>
    

相关问题