[英]Azure Websites + node.js - Cannot GET /
When deploying a node.js / express app to Azure Websites I am getting "Cannot GET /" error in the browser.将 node.js / express 应用程序部署到 Azure 网站时,我在浏览器中收到“无法获取 /”错误。 The same application runs flawlessly on the local machine.相同的应用程序可以在本地机器上完美运行。
web.config
is standard (I only removed the Static Rewrite rule), so: 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>
Code is deployed in src/server/
(node functions) and src/client/
(static content) folders.代码部署在src/server/
(节点函数)和src/client/
(静态内容)文件夹中。
As per the FREB logs the src/server/apps.js is fetched, but in the end the following error is thrown:根据 FREB 日志,获取了 src/server/apps.js,但最终抛出以下错误:
ErrorCode The system cannot find the file specified. (0x80070002)
Inside app.js
I have the following configuration for static files:在app.js
我对静态文件有以下配置:
app.use(express.static('./src/client/'));
Azure Websites runs node from the folder where the file defined in the package json
as the start file is located, so eg for the following: Azure 网站从package json
定义为启动文件的文件所在的文件夹运行节点,例如以下内容:
"start": "node src/server/app.js"
fact it will run node app.js
from the src/server
folder (you can find there also the iisnode.yml
file).事实上,它会从src/server
文件夹运行node app.js
(你也可以在那里找到iisnode.yml
文件)。 Which results in all relative paths getting messed up.这导致所有相对路径变得混乱。 One solution for this is to use absolute paths, so eg:一种解决方案是使用绝对路径,例如:
app.use(express.static('D:/home/site/wwwroot/src/client/'));
and switching between paths using eg process.env.NODE_ENV
variable.并使用例如process.env.NODE_ENV
变量在路径之间切换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.