0

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:

  1. Is it really an IIS issue?
  2. If it is, how can I fix that in Azure?
Community
  • 1
  • 1
Nate
  • 7,606
  • 23
  • 72
  • 124

1 Answers1

1

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, enter image description here

If you are using Express, you can also do the same thing with the code below,

app.use(express.static('public'))
Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
  • Where is the `web.config` file? None of my css, js and img files are loading in Azure web app (404, Not Found), but they load fine locally, I am using this in my app code `app.use(express.static("dist"));`. – user1063287 Sep 05 '20 at 07:09
  • Having the same issue 2 years after my last comment, can't remember how I resolved it :(. – user1063287 Dec 26 '22 at 04:10