Point iisnode at server.js file nested in folder i

2019-07-15 11:29发布

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>

2条回答
相关推荐>>
2楼-- · 2019-07-15 12:19

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');

查看更多
相关推荐>>
3楼-- · 2019-07-15 12:22

I struggled it with a bit and here is my solution without any additional file

Handler

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

        <!-- Remote debugging (Azure Website with git deploy): Uncomment NtvsDebugProxy handler below.
        Additionally copy Microsoft.NodejsTools.WebRole to 'bin' from the Remote Debug Proxy folder.-->
        <!--<add name="NtvsDebugProxy" path="ntvs-debug-proxy/7afabecd-23d0-4ac1-a682-c36ef59e1480" verb="*" resourceType="Unspecified"
          type="Microsoft.NodejsTools.Debugger.WebSocketProxy, Microsoft.NodejsTools.WebRole"/>-->
</handlers>

Rewite rule

<rewrite>
        <rules>
            <clear/>
            <!-- Remote debugging (Azure Website with git deploy): Uncomment the NtvsDebugProxy rule below. -->
            <!--<rule name="NtvsDebugProxy" enabled="true" stopProcessing="true">
              <match url="^ntvs-debug-proxy/.*"/>
            </rule>-->
            <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="iisnode.+" negate="true"/>
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
                <action type="Rewrite" url="dist/index.js"/>
            </rule>
        </rules>

So as you can see my app entry point is in dist/index.js

Gabor

查看更多
登录 后发表回答