I am trying to deploy a Node.js application on IIS. I saw the samples on the GitHub repository (https://github.com/tjanczuk/iisnode/tree/master/src/samples).
I am stuck at serving static files. Like a normal Node application, I stored the static files in a folder named public. As per suggestions on several blogs/forums I added the following rule to web.config:
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
But it doesn't work. If anyone has a sample application demonstrating this issue, it would be of great help.
In case anyone comes across this question on Google and had problems with the sample web.config mentioned in the accepted answer...
This is the web.config file that worked for me:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server/app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode" />
</rule>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server\/app.js\/debug[\/]?" />
</rule>
<rule name="StaticContent" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="public/{C:1}" logRewrittenUrl="true" />
<conditions>
<add input="{REQUEST_URI}" pattern=".*?virtualpath\/(.*)" />
</conditions>
</rule>
<rule name="DynamicContent" patternSyntax="ECMAScript">
<match url=".*" />
<conditions>
<add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="server/app.js" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
My folder structure is:
Check out a sample iisnode web.config that redirects requests for static files in the public
folder to the IIS's static file handler instead of Node.js at http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With