node.js - 网站部署到 Azure keystone.js 时出错

标签 node.js azure webserver azure-web-app-service keystonejs

我正在尝试将一个在 Node.js 中内置的普通 keystone.js 入门应用程序部署到 Azure 网站的共享层。

部署后出现错误

由于发生内部服务器错误,该页面无法显示。

我认为这可能是因为主服务器文件名为 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 网站的配置选项卡上将平台设置为 64 位。然后,我在 Node 项目的根目录下创建了一个 IISnode.yml 文件,其中包含以下内容:

loggingEnabled: true
devErrorsEnabled: true

现在,当我通过浏览器访问该站点时,我看到了详细的错误消息,这表明 cloudinary 环境变量未配置。我将项目 .env 文件中存储的内容添加到我的 azure 网站门户页面的配置选项卡上的应用程序设置中,这解决了所有问题!

关于node.js - 网站部署到 Azure keystone.js 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24943307/

相关文章:

javascript - Mongoose findOneAndUpdate : create and then update nested array

javascript - Nodejs - 设置不同的 api 版本

node.js - 如何在nodejs中使用curl -F?

azure - Microsoft Azure 信息保护中是否有一次性密码选项?

sql-server - SSMS - 无法使用本地计算机上的 SSMS 连接到 Azure VM 上的 SQL Server 2017 Express

c# - Microsoft 云服务/辅助角色部署 - 未找到方法?

configuration - 如何配置jetty监听多个端口

node.js - 针对多个 Node 模块版本进行测试

html - 一种 CSS 样式仅适用于本地主机而不适用于服务器托管

java - 网络服务器用什么编程语言