【问题标题】:Svgs and other mime types in windows azureWindows azure 中的 Svgs 和其他 mime 类型
【发布时间】:2015-07-29 03:23:42
【问题描述】:

您好,我在 Windows azure 上的 nodejs 中建立了一个网站,并希望将 svg 包含为背景图像。我一般如何允许 svg 和 mimetypes?

【问题讨论】:

    标签: node.js azure svg mime-types


    【解决方案1】:

    Azure 使用IISNode

    我添加了这个 web.config 文件来让 svgs 工作。 可以针对其他 mime 类型进行修改

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <staticContent>
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
        </staticContent>
        <handlers>
          <add modules="iisnode" name="iisnode" path="server.js" verb="*"/>
        </handlers>
        <rewrite>
          <rules>
            <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$"/>
            </rule>
            <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^server.js\/debug[\/]?"/>
            </rule>
            <rule name="StaticContent">
              <action type="Rewrite" url="public{REQUEST_URI}"/>
            </rule>
            <rule name="DynamicContent">
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
              </conditions>
              <action type="Rewrite" url="server.js"/>
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    【讨论】:

      【解决方案2】:

      如果 Node 正在提供文件,只需使用正确的 MIME 类型提供它(使用您正在使用的任何库)。如果您让 IIS 提供文件,那么您需要将 MIME 类型添加到您的 web.config。

      【讨论】:

      • 只是添加对如何将 mime-type 添加到 IIS 的参考:iis.net/ConfigReference/system.webServer/staticContent/mimeMap
      • 当我在本地运行节点时(通过 express 使用 node-mime),节点可以很好地提供文件,但是当我推送到 azure 时,svg 没有加载。
      • 它为他们发送了什么 Content-Type 标头?
      • 我真的不知道如何找到它,但是如果问题仅存在于 azure 上,那么问题就一定是节点服务器尝试从底层系统获取文件时=
      • 文件系统与服务器发送的 HTTP 标头没有任何关系。如果您不知道 Content-Type 标头(MIME 类型)是什么,您怎么知道这是问题所在?您看到的实际症状是什么?
      猜你喜欢
      • 2016-04-10
      • 1970-01-01
      • 2014-09-17
      • 2011-03-27
      • 2020-07-12
      • 1970-01-01
      • 2014-01-06
      • 2019-08-13
      • 2010-11-04
      相关资源
      最近更新 更多