首页 > 解决方案 > IIS 10 - 即使在配置 MIME 和处理程序之后,JSON 文件也无法提供服务

问题描述

我已经在从 Node.js 构建的 IIS 10 (Windows 10) 中部署了一个 Web 应用程序。

文件结构

文件结构


我无法使用直接 URL 访问 JSON 文件(例如http://localhost:3000/manifest.json )。

收到以下错误, 我已将 MIME 类型设置如下,
错误

MIME 类型 - JSON

我也尝试过处理程序映射,

JSON的处理程序映射


我的 web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Static Assets" stopProcessing="true">
          <match url="([\S]+[.](html|htm|svg|js|css|png|gif|jpg|jpeg|json))" />
          <action type="Rewrite" url="/{R:1}" />
        </rule>
        <rule name="ReactRouter Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>
    <handlers>
      <add name="StaticFileModuleJson" path="*.json*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
    </handlers>
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

标签: node.jsjsoniisstaticmime

解决方案


我注意到您的重写规则已将 .json 重写为 .js。它与处理程序无关,因为静态文件处理程序仍在处理请求。

在此处输入图像描述 在此处输入图像描述

请交换js和json的索引。

 <rule name="Static Assets" stopProcessing="true">
      <match url="([\S]+[.](html|htm|svg|json|css|png|gif|jpg|jpeg|js))" />
      <action type="Rewrite" url="/{R:1}" />
    </rule>

在此处输入图像描述


推荐阅读