IISNode and Express 3 yields http 403.13 error
Asked Answered
P

3

5

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.

Pea answered 11/9, 2012 at 18:29 Comment(0)
P
7

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>
Pea answered 11/9, 2012 at 19:22 Comment(1)
I tried your solution and I am still getting this error. Any ideas?Fulfill
I
3

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.
Including answered 11/9, 2012 at 23:35 Comment(0)
A
1

Fin more info in my link there I have a working example a the bottom of the question

Below its the project configuration

enter image description here

below the code for server.js

 "use strict";

 var express = require('express');
 // determind what mode we are
 var env = process.env.NODE_ENV = process.env.NODE_ENV||'developemnt';
 var app = express();
 //configure the view engine

 app.set('views', __dirname + '/views');
 app.engine('html', require('ejs').renderFile);
 app.set('view engine', 'html');

 //app.use('/public', express.static(__dirname + '../public'));

 //the asterisk handles all routes includes javascript, css, html request...
 app.get('*', function (req , res) {
        res.render('index');
 });
 var PORT = 3030;
 app.listen((process.env.PORT!==undefined)?process.env.PORT:PORT);
 console.log('Listening to PORT : ' + process.env.PORT );

Below the index.html

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
  <base href="/">
  <title></title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">
  </head>
  <body ng-app="idetikApp">
  <div ng-view=""></div>
    <script src="app/app.js"></script>
  </body>

</html>

web.config

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

app.js

angular.module('idetikApp', [ 'ngResource', 'ngRoute']);

angular.module('idetikApp').config(function ($routerProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
  $routerProvider.when('/', {templateUrl: '/partials/main', controller:'mainctrl'})

});

angular.module('idetikApp').controller('mainctrl', function ($scope) {
  $scope.mayvar = "hello world"
})

and the main.html

<h1>this is a partial</h1>
<h2>{{myvar}}</h2>

and my folder structure

enter image description here

but now I cant find my files inside public :(

enter image description here

Apis answered 15/4, 2016 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.