Hi im setting up a website in nodejs on windows azure, and would like to include svg's as background images. how do i allow svgs and mimetypes in general?
2 Answers
Azure uses IISNode
I added this web.config file to get svgs working. It can be modified for other mime types
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
</staticContent>
<handlers>
<add modules="iisnode" name="iisnode" path="server.js" verb="*"/>
</handlers>
<rewrite>
<rules>
<rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$"/>
</rule>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?"/>
</rule>
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If Node is serving up the file, just serve it up with the right MIME type (using whatever library you're using). If you're having IIS serve up the file, then you'll need to add the MIME type to your web.config.
-
Just to add reference to how to add mime-type to IIS: iis.net/ConfigReference/system.webServer/staticContent/mimeMap– astaykovCommented Jul 24, 2012 at 7:42
-
Node is serving up the files fine when i run it locally (using node-mime via express), but when i push to azure the svgs are not loaded. Commented Jul 24, 2012 at 10:08
-
-
I dont really know how to find that, but if the problem only consists on azure, wouldnt the problem have to be when the node server tries to get the files from the underlying system= Commented Jul 24, 2012 at 12:28
-
The file system doesn't have anything to do with the HTTP headers your server sends. If you don't know what the Content-Type header (MIME type) is, how do you know that it's the issue? What's the actual symptom you're seeing? Commented Jul 24, 2012 at 17:23