关于node.js:在Azure中获取.css文件时出错

Error when fetching .css files in Azure

我在Azure上有一个nodejs应用程序(作为Web应用程序安装),尝试获取样式表(.css)时收到以下消息:

1
Resource interpreted as Stylesheet but transferred with MIME type text/html

我已阅读到问题是IIS配置,所以我的问题是:

  • 真的是IIS问题吗?
  • 如果是的话,如何在Azure中修复该问题?

  • 根据我的经验,我认为这不是IIS问题。
    看来您是在以自己的方式提供静态文件。
    在Azure Web Apps中,我们不需要这样做,
    如果查看web.config文件中的以下几行,您会发现IIS服务器已经可以处理/ public目录中的静态内容,例如图像,CSS文件和JavaScript文件。
    因此,我们只需在项目的根目录下添加一个名为public的文件夹,然后将静态文件放在其中。

    1
    2
    3
    4
    <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
    <rule name="StaticContent">
       
    </rule>

    例如,项目结构如下所示,
    enter

    如果您使用的是Express,还可以使用下面的代码做同样的事情,

    1
    app.use(express.static('public'))