我正在寻找慢慢转换Node.js
应用程序转移到ASP.NET WebAPI 2.0
。我目前正在使用IIS
并会坚持IIS
。因此,我想将它们托管在同一台服务器上,但将一些 URI 定向到新平台。
我将如何在web.config
?目前的web.config
for node.js
看起来像这样:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the app.js file is a node.js application
to be handled by the iisnode module -->
<add name="iisnode" path="beta/app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^beta/app.js\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="beta/public{REQUEST_URI}" />
</rule>
<!-- All other URLs are mapped to the Node.js application entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="beta/app.js" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>
文件结构为:
- web.config (the one shown above)
-> node
- app.js
- ...
-> webapi
- web.config
- global.asax
- ...
我在想我应该编写一条新规则,列出要访问的 URIWebAPI
。但是,我不太确定该怎么做。我的猜测是我会为每个添加一个条件URI
与input
属性。我也在想我应该指出ASP.NET WebAPI
项目,但我更不知道应该如何去做,因为Node.js
我只是指着app.js
file.
好吧,这就是我最终所做的。它实际上非常简单。但是,当您不熟悉 IIS 时,这可能会令人望而生畏。
我把原来的web.config
与node
目录。我觉得iisnode
处理程序干扰WebAPI
配置,如果你不这样做。所以,新的node.js
web.config
in the node
目录看起来像这样:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the app.js file is a node.js application
to be handled by the iisnode module -->
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^app.js\/debug[\/]?" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>
对于根web.config
我让它直接指向静态文件,绕过node.js
。这意味着我将不得不编写一些自定义代码来处理重写gzipped
文件 - 我稍后会解决这个问题。我还添加了属性stopProcessing
每一个rewrite
rule
。这也弄乱了代码,因为它实际上也不会重写我想要的地方,因为重写会被覆盖。请注意,accept
版本控制标头实际上尚未经过测试 - 但我没有任何理由相信它不起作用。最后rewrite
全部点uri
到webapi
默认情况下应用程序。
In the WebAPI
我必须将所有路线路由到的项目webapi/api
因为它不在根文件夹中。在我将所有内容迁移后node.js
我可能会做webapi
目录项目的根文件夹,因此不需要webapi
在我的路由中了。但这对客户来说都是隐藏的。
所以这是实际的代码:
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- test item for webapi folder -->
<rule name="StaticContent2" stopProcessing="true" >
<conditions>
<add input="{REQUEST_URI}" pattern="^/def" />
</conditions>
<action type="Rewrite" url="webapi{REQUEST_URI}" />
</rule>
<!-- rewrite static items which exist on node -->
<rule name="Node Static" stopProcessing="true" >
<conditions>
<add input="{REQUEST_URI}" pattern=".*\.[A-Za-z2]{2,5}$" />
</conditions>
<action type="Rewrite" url="node/public{REQUEST_URI}" />
</rule>
<rule name="WebAPI Version 2" stopProcessing="true">
<conditions>
<add
input="{HEADER_ACCEPT}"
pattern="vnd.fieldops.v2"
ignoreCase="true"
/>
</conditions>
<action type="Rewrite" url="webapi{REQUEST_URI}" />
</rule>
<!-- rewrite to node for dynamic items -->
<rule name="Node Dynamic" stopProcessing="true" >
<conditions>
<add
input="{REQUEST_URI}"
pattern="^/api/(dealerservicereports|chat|dealers|dealerequipment|dealercloseout|publications|tokens|users|\?)"
ignoreCase="true"
/>
</conditions>
<action type="Rewrite" url="node/app.js" />
</rule>
<!-- rewrite everything else to webapi -->
<rule name="WebAPI Dynamic" stopProcessing="true" >
<action type="Rewrite" url="webapi{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)