【发布时间】:2014-07-29 22:37:13
【问题描述】:
我正在尝试将 node.js 中内置的普通 keystone.js 启动应用程序部署到 Azure 网站的共享层。
部署后出现错误
The page cannot be displayed because an internal server error has occurred.
我认为可能是因为主服务器文件名为keystone.js,所以我将其重命名为index.js。这没有解决它。
接下来,我认为这可能是个问题,因为 keystone 默认为端口 3000,所以我在 index.js 文件中添加了端口信息。这里是:
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').load();
// Require keystone
var keystone = require('keystone');
// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.
keystone.init({
'name': 'Magic Site',
'brand': 'Magic Site',
'less': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'jade',
'mongo': "redacted",
'port': process.env.PORT || 1337,
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
'cookie secret': 'redacted'
});
// Load your project's Models
keystone.import('models');
// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set('locals', {
_: require('underscore'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable
});
// Load your project's Routes
keystone.set('routes', require('./routes'));
// Setup common locals for your emails. The following are required by Keystone's
// default email templates, you may remove them if you're using your own.
// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
'posts': ['posts', 'post-categories'],
'galleries': 'galleries',
'enquiries': 'enquiries',
'users': 'users'
});
// Start Keystone to connect to your database and initialise the web server
keystone.start();
仍然没有运气。但是,这在我的本地机器上效果很好,只是在 Azure 中不行。有什么想法吗?
更新:我将我的主服务器文件更新为“server.js”。我做了一些挖掘并查看了 Azure 中的部署日志,发现:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling node.js deployment.
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
Deleting file: 'index.js'
Copying file: 'package.json'
Copying file: 'server.js'
Using start-up script server.js from package.json.
Generated web.config.
Node.js versions available on the platform are: 0.6.17, 0.6.20, 0.8.2, 0.8.19, 0.8.26, 0.8.27, 0.10.5, 0.10.18, 0.10.21, 0.10.24, 0.10.26, 0.10.28, 0.10.29.
Selected node.js version 0.10.29. Use package.json file to choose a different version.
Updating iisnode.yml at D:\home\site\wwwroot\iisnode.yml
Finished successfully.
【问题讨论】:
-
您是如何将项目上传到 azure 的?你用过Kudu吗?或者只是使用 FTP 复制您的内容?您将需要一个 web.config 来配置 iisnode 以指向您的主脚本,即 index.js 或 keystone.js。在您的本地机器上,您是否使用 iisnode 尝试过此应用程序?
-
@RanjithRamachandra 我在 Bitbucket 中有我的源代码,我正在使用 Azure 网站“从源代码控制部署”选项。我在mac上做我的开发,所以我没有使用iisnode。我应该将 web.config 文件放在我的项目中的什么位置,我应该在其中放置什么?
-
从上面的日志中,你应该已经有了 Kudu 自动创建的 web.config。我会自己尝试一下,让你知道我的发现。顺便说一句,你在哪里配置数据库?
-
@RanjithRamachandra 我正在为我的数据库使用 Azure 中的 mongoLab 插件。在本地运行我的应用程序时,我可以毫无问题地建立 mongoLab 连接。
标签: node.js azure webserver azure-web-app-service keystonejs