css - React 基本应用程序在本地工作,但在 Azure 中它不加载 .CSS、.Ico、.JSON

标签 css reactjs azure react-router

我有一个可以在本地运行的 Web 应用程序,当使用发布管道部署到 Azure 时,所有文件似乎都已正确部署 enter image description here

当我访问网站的 .css url 时,该文件未加载到浏览器中,并且出现 404 错误。

enter image description here

index.html 非常简单:

<!doctype html><html lang="en" dir="ltr"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="icon" type="image/png" sizes="32x32" href="/favicon.png"><link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700" rel="stylesheet" async><link async rel="stylesheet" href="/css/ionicons.min.css"><link rel="stylesheet" href="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dba9bebab8aff6b2b5a8afbab5afa8bebaa9b8b3f6afb3beb6bef6bab7bcb4b7b2ba9beff5ebf5eb" rel="noreferrer noopener nofollow">[email protected]</a>/style.min.css"><link rel="stylesheet" href="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99f5fcf8fff5fcedd9a8b7abb7a9" rel="noreferrer noopener nofollow">[email protected]</a>/dist/leaflet.css" integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" crossorigin="" async/><title>Isomorphic</title><link href="/static/css/main.48941814.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.b47e17ce.js"></script></body></html>

如第一个屏幕截图所示,文件就在那里:

我唯一能想到的是 web.config 有问题,它不允许提供 .css 或其他类型的文件?:

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

最佳答案

我会查看StaticContent规则,它似乎重写了对public文件夹的所有请求,并且从您发布的控制台图像来看,您的静态内容不在公开下。

希望对你有帮助!

关于css - React 基本应用程序在本地工作,但在 Azure 中它不加载 .CSS、.Ico、.JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53291035/

相关文章:

azure - AADSTS90002 : Tenant 'xx' not found. 如果租户没有事件订阅,则可能会发生这种情况

c# - 使用 ImageMagick 将图像压缩为 azure blob

wcf - 在azure中重新发布服务

html - 仅使用 Flex 功能创建特殊网格

javascript - 有没有办法检测用户使用的是旧显示器还是带有 css 或 js 的新显示器?

javascript - React-router服务端渲染和ajax取数据

css - 更改光标类型 - Material UI 扩展面板

css - 检查 css 是否加载外部文件

php - 如何将表单数据存储在 MULTIPAGE 表单中?

javascript - 如何更新这个已弃用的 React.PropTypes 代码