新版本的Express将模块与"服务器"文件分开.它现在存在,/bin/www如果可能的话,我更愿意遵守这个惯例.
在package.json文件中,"start"脚本明确指向正确的位置,但Azure似乎忽略了这一点.
如何server.js在根目录中没有文件的情况下部署Express 4.x应用程序?我需要做的就是让它自动调用节点./bin/www而不是节点server.js.是否有另一个根配置文件,我可以添加特定于云主机(Azure?)这是我如何在Heroku等工作.
Tim*_*ple 14
Azure团队已经在内部修复了这个问题.新部署的express 4应用程序应该可以在Azure网站上正常运行而无需任何其他更改.
我将从tl开始;博士.在应用程序的根目录中创建web.config文件并使用此xml.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<!--
By default IIS will block requests going to the bin directory for security reasons.
We need to disable this since that's where Express has put the application entry point.
-->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin" />
</hiddenSegments>
</requestFiltering>
</security>
<handlers>
<!-- Indicates that the www file is a node.js entry point -->
<add name="iisnode" path="/bin/www" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^bin\/www\/debug[\/]?" />
</rule>
<!--
First we consider whether the incoming URL matches a physical file in the /public folder.
This means IIS will handle your static resources, and you don't have to use express.static
-->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<!-- All other URLs are mapped to the node.js entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="/bin/www"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这有点乱,需要一段时间才能追踪.我真的希望看看package.json是否足够聪明,但这是我们现在要处理的问题.通常,Azure通过检查app.js或server.js文件来确定它是否是Node应用程序.如果找到该文件,它将自动创建一个非常类似于上面的web.config文件.在这种情况下,它将检测app.js,但与99%的其他节点应用程序不同,这实际上不是入口点.我们要做的是将入口点更改为/ bin/www,如上所示.
我们遇到的另一个问题是,出于安全原因,IIS默认阻止对bin文件夹的请求.我们可以重命名快递bin文件夹,或告诉IIS克服它.这就是xml文件的hiddenSegments部分.
| 归档时间: |
|
| 查看次数: |
2597 次 |
| 最近记录: |