Search code examples
node.jsiisurl-rewritingiisnode

Point iisnode at server.js file nested in folder in an iis website


I having trouble getting iisnode to run my node application. My directory structure is

iis-site
   -client
   -server
      -server.js

How can I get iisnode to point to a nested .js file? I tried this, but it servers the server.js instead of executing it.

<handlers>
    <add name="iisnode" path="server\server.js" verb="*" modules="iisnode" />
</handlers>

and

<rule name="default">
       <match url="/*" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
        <action type="Rewrite" url="server/server.js" />
</rule>

Solution

  • I ended up posting this as an issue on the GitHub project and got an answer there.

    Basically, the approach is to keep a .js file in the root of the directory that requires the .js that bootstraps your application.

    Ex:

    <handlers>
        <add name="iisnode" path="iisnode.js" verb="*" modules="iisnode" />
    </handlers>
    

    and

    <rule name="default">
           <match url="/*" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
            <action type="Rewrite" url="iisnode.js" />
    </rule>
    

    and in iisnode.js there is one line of code: require(__dirname + '\\server\\server.js');