我试图在OpenShift 3启动器上部署我的node.js应用程序。部署处于活动状态,未报告任何错误。但是当我试图访问该网站时,"应用程序不可用"显示。当我尝试在heroku上部署它时发生了类似的问题。
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mainCtrl = require('./controllers/mainCtrl');
var session = require('client-sessions');
//set up template engine
app.set('view engine', 'ejs');
app.set('views', __dirname + '/public/views');
//middleware
app.use(express.static(__dirname + '/public/assets'));
app.use(session({
cookieName: 'session',
secret: 'jfsa6a5sef6wea4f535641fds53s3das12d',
duration: 180 * 60 * 1000,
activeDuration: 180 * 60 * 1000,
http: true
}));
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
//database
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
//connect to database
var database = 'mongodb://test:test@ds153400.mlab.com:53400/open_comments';
mongoose.connect(database);
//create a schema
const commentSchema = new mongoose.Schema({
http: String,
domain: String,
account: String,
content: {
user: String,
date: Date,
comment: String,
votes: Number
}
});
const accountSchema = new mongoose.Schema({
account: {type: String, unique: true},
user: String,
email: {type: String, unique: true},
password: String,
history: [],
bookmarks: [],
notifications: []
});
//create a model
//for comments
var Comments = mongoose.model('Comments', commentSchema);
//for account info
var Account = mongoose.model('Account', accountSchema);
//for https
var fs = require('fs');
var https = require('https');
var options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
mainCtrl(app, Comments, Account);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(process.env.OPENSHIFT_NODEJS_PORT || 8080);
服务器在本地运行良好。我可以提出的一个问题是,默认情况下,openshift使用的是http而不是https。但我只为https提供了端口,因为只允许一次监听。
更新 我删除了https服务器并重建了它。它现在正在运作。我不知道发生了什么,但谢谢你,Graham Dumpleton!