用issnode+IIS来托管NodeJs Server之四:支持Debug

这几篇文章是一个系列的:

  1.  用issnode+IIS来托管NodeJs Server之一:安装篇
  2.  用issnode+IIS来托管NodeJs Server之二:移植
  3.  用issnode+IIS来托管NodeJs Server之三:加入Windows集成验证功能
  4.  用issnode+IIS来托管NodeJs Server之四:支持Debug


本来以为iisnode的集成已经很完美了,今天突然想使用下iisnode的调试与日志,所以就作了一些研究,发现真的很不错!我的设置,基本上是参照这篇文章的:http://tomasz.janczuk.org/2011/11/debug-nodejs-applications-on-windows.html


第一,iisnode本身就支持debug模式,使用Chrome访问 http://localhost/app.js/debug,这个URL就进入了debug模式了,可以设置断点,可以单步调试。

第二,但是对于expressJs框架的程序来说,因为URL被重写了,所以简单的使用/debug这个URL是无效的。怎么办呢?也比较简单,在web.config里面写一句话就行了:

  <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
    <match url="^app.js/debug[/]?" />
  </rule>

这个意思是说,假如URL匹配 /app.js/debug,那么就不要进行URL重写。我再配置过程中,发现了一些问题,就是浏览器有记忆功能,所以每当你修改了web.config,最好是重启一下IIS服务器、重启一下浏览器,再按Ctrl+F5清一下缓存,在测试。

第三,因为服务器进入了debug状态就不会自己退出,所以需要显式访问 /debug/?kill来退出调试状态。


最后贴一下我的配置文件。为了安全起见,我把/debug改成了/debug_private,这样比较安全:

<configuration>
    <system.webServer>

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

        <rewrite>
            <rules>
                <clear />

                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^app.js/debug_private[/]?" />
                </rule>

                <rule name="mysite" enabled="true">
                    <match url="/*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="app.js" />
                </rule>

            </rules>
        </rewrite>

        <defaultDocument>
            <files>
                <add value="app.js" />
            </files>
        </defaultDocument>

        <iisnode
            promoteServerVars="AUTH_USER,AUTH_TYPE"
            debuggerPortRange="5058-6058"
            debuggerPathSegment="debug_private"
            maxNamedPipeConnectionRetry="3"
            namedPipeConnectionRetryDelay="2000"
        />

    </system.webServer>
    <system.web>
        <identity impersonate="false" />
    </system.web>
</configuration>




原文地址:https://www.cnblogs.com/puncha/p/3876898.html