Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IISNode and Express 3 yields http 403.13 error

I am setting up IISNode on IIS 7 locally on my Win7 box. I followed the instructions on the site and the samples are working fine.

I created a new website and AppPool in IIS Manager to run a brand new shell of an Express site. I've added the web.config to tie the iisnode module to my starting .js file.

When I browse to the default route (/) I get an Http 403.14 error (Server is configured to not list the contents of the directory).

I have attempted to remap the IISNode sample directory to where my Express app is and the same error occurs.

If I attempt to go to a non-existing route, I DO get Connect's 404 error message of Cannot VERB ROUTE.

I feel like I"m missing something simple and (hopefully obvious).

Has anyone ran into this and can provide me some insight? Looking online has provided little light in terms of even when I can check.

like image 731
JamesEggers Avatar asked Dec 21 '22 16:12

JamesEggers


2 Answers

I figured out what issue I was having. In my web.config, I had the default IISNode section and the handler section to map the iisnode module to my app.js file.

However, when using Express, every route has to go through that file. So by adding the rewrite section as below it resolved my issue.

<rewrite>
  <rules>
    <rule name="Catch All">
      <match url="/*" />
      <action type="Rewrite" url="app.js" />
    </rule>
  </rules>
</rewrite>
like image 167
JamesEggers Avatar answered Dec 23 '22 04:12

JamesEggers


For a more advanced URL rewriting configuration check out the web.config template at http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html. This template allows you to redirect requests for static content to the IIS static file handler, as well as retain access to iisnode logs over HTTP.

    <?xml version="1.0" encoding="utf-8"?>  
<configuration>  
    <system.webServer>           
      <handlers>  
           <add name="iisnode" path="server.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.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>

The web.config above has the following effect:

  1. It specifies server.js as the entry point to your node.js application.
  2. It redirects all requests for URLs that map to physical files in the “public” subdirectory to an IIS static file handler. Using IIS static file handler has a large performance benefit compared to serving static content from within a node.js application. The handler leverages IIS and OS low level caching mechanisms which offer superb performance.
  3. It allows IIS to serve the log files that capture output of a node.js application as static files such that you can access them over HTTP. By default, if your server.js entry point is reached at http://example.com/server.js, the log files would be accessible at http://example.com/iisnode.
  4. It exposes the built-in node-inspector debugger at http://example.com/server.js/debug. Learn more about debugging with iisnode.
  5. It sends all other HTTP requests to be processed by your node.js application in server.js.
like image 37
Tomasz Janczuk Avatar answered Dec 23 '22 06:12

Tomasz Janczuk