在Azure中获取.css文件时出错 [英] Error when fetching .css files in Azure
问题描述
我在Azure上有一个nodejs应用程序(作为Web应用程序安装),尝试获取样式表(.css)时收到以下消息:
资源解释为样式表,但以MIME类型text/html传输
我已经
如果您使用的是 Express ,则也可以使用下面的代码做相同的事情,
app.use(express.static('public'))
I have a nodejs app on Azure (installed as a webapp) and I'm getting the following message when trying to fetch stylesheets (.css):
Resource interpreted as Stylesheet but transferred with MIME type text/html
I have read that the problem is an IIS config so my questions are:
- Is it really an IIS issue?
- If it is, how can I fix that in Azure?
Per my experience, I don't think this is an IIS issue.
It seems that you are serving static files by your own way.
In the Azure Web Apps, we don't need to do that,
if you take a look at the following lines in the web.config
file you will find that the IIS server already handles serving up the static content such as images, CSS files, and JavaScript files from the /public directory.
So we can just add a folder named public
under the project's root directory and then put the static files in where.
<!-- 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>
For example, the project structure looks like this,
If you are using Express, you can also do the same thing with the code below,
app.use(express.static('public'))
这篇关于在Azure中获取.css文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!