Azure网站+ node.js – 无法获取/

将一个node.js / express应用程序部署到Azure网站时,在浏览器中出现“无法获取/”错误。 相同的应用程序在本地机器上完美运行。

web.config是标准的(我只是删除了静态重写规则),所以:

  <!-- All other URLs are mapped to the node.js site entry point --> <rule name="DynamicContent"> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> </conditions> <action type="Rewrite" url="src/server/app.js"/> </rule> </rules> 

代码部署在src/server/ (节点函数)和src/client/ (静态内容)文件夹中。

根据FREB日志提取src / server / apps.js,但最后引发下面的错误:

 ErrorCode The system cannot find the file specified. (0x80070002) 

app.js里面我对静态文件有如下configuration:

  app.use(express.static('./src/client/')); 

Azure网站运行节点从文件夹package json定义的文件作为起始文件所在的位置,例如:

 "start": "node src/server/app.js" 

实际上它会从src/server文件夹运行node app.js (你也可以在这里findiisnode.yml文件)。 这导致所有相对path被搞乱。 一个解决scheme是使用绝对path,例如:

 app.use(express.static('D:/home/site/wwwroot/src/client/')); 

并使用例如process.env.NODE_ENVvariables在path之间切换。