Serving static files in IISNODE by rewriting StaticFiles URLs

I am trying to deploy a Node.js application in IIS. I saw the samples in the GitHub repository ( https://github.com/tjanczuk/iisnode/tree/master/src/samples ).

I am stuck with serving static files. Like a regular Node application, I saved static files in a folder called public. As suggested by several blogs / forums, I added the following rule to web.config:

<rule name="StaticContent"> <action type="Rewrite" url="public{REQUEST_URI}"/> </rule> 

But that will not work. If someone has an example application demonstrating this problem, this will be very helpful.

+7
iisnode
source share
2 answers

Check out the iisnode web.config sample, which redirects requests for static files in the public folder to the IIS static file handler instead of Node.js at http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode. html

+5
source share

If someone comes across this question on Google and is having problems with the web.config sample 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:

  • virtualpath / - refers to the configured IIS virtual path
    • public / - contains static content
    • server / - contains server application files
+7
source share

All Articles