无法启动托管在 Azure 中的 nodejs web api
cannot start nodejs web api hosted in Azure
学习 nodejs
并开始使用 restify 创建我自己的 restful API。
我创建了一个非常简单的 server.js
文件,其中基本上包含一个 hello world 类型的示例,启动方式如下:
server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
在本地运行良好。我打不过http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.
我已经将代码部署到 bitbucket 中,现在我想使用 App Services
.
在 Azure 中托管这些 API
我的项目结构是这样的:
/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html
当我在 Azure 中设置新的应用程序服务时,我可以看到部署从 BB 接收代码,但该服务从未响应我的请求。
我已经设置了应用程序的主路径:/site/wwwroot/topfolder/myproject
,当我导航到 http://myproject.azurewebsites.net 时我可以看到 index.html
,这很好。
我实际上遇到了 404 错误:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
有很多关于如何使用 bitbucket 设置持续部署的示例,在大多数情况下,它们似乎都有效,但我的 server.js
文件似乎没有被调用或启动。
我如何调试这里发生的事情?
packages.json
Azure 在这种情况下使用的文件吗?
谢谢。
作为托管在 Azure 应用服务上的应用程序的根目录路径,是 D:\home\site\wwwroot
。而对于nodejs应用,Azure fabric会在根目录下找到入口脚本,如server.js
。并且请求通过根目录中的 web.config
处理。如果缺少 server.js
或 web,config
文件,则会出现 404 错误。
您可以尝试修改或修改应用程序的结构,例如:
-/node_modules
-/node_modules...
server.js
package.json
index.html
然后,您通过 GIT 或从 BB 将您的应用程序部署到 Azure,Azure 部署任务将 运行 命令 npm install
并在根目录.
如有任何疑问,请随时告诉我。
学习 nodejs
并开始使用 restify 创建我自己的 restful API。
我创建了一个非常简单的 server.js
文件,其中基本上包含一个 hello world 类型的示例,启动方式如下:
server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
在本地运行良好。我打不过http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.
我已经将代码部署到 bitbucket 中,现在我想使用 App Services
.
我的项目结构是这样的:
/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html
当我在 Azure 中设置新的应用程序服务时,我可以看到部署从 BB 接收代码,但该服务从未响应我的请求。
我已经设置了应用程序的主路径:/site/wwwroot/topfolder/myproject
,当我导航到 http://myproject.azurewebsites.net 时我可以看到 index.html
,这很好。
我实际上遇到了 404 错误:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
有很多关于如何使用 bitbucket 设置持续部署的示例,在大多数情况下,它们似乎都有效,但我的 server.js
文件似乎没有被调用或启动。
我如何调试这里发生的事情?
packages.json
Azure 在这种情况下使用的文件吗?
谢谢。
作为托管在 Azure 应用服务上的应用程序的根目录路径,是 D:\home\site\wwwroot
。而对于nodejs应用,Azure fabric会在根目录下找到入口脚本,如server.js
。并且请求通过根目录中的 web.config
处理。如果缺少 server.js
或 web,config
文件,则会出现 404 错误。
您可以尝试修改或修改应用程序的结构,例如:
-/node_modules
-/node_modules...
server.js
package.json
index.html
然后,您通过 GIT 或从 BB 将您的应用程序部署到 Azure,Azure 部署任务将 运行 命令 npm install
并在根目录.
如有任何疑问,请随时告诉我。