【发布时间】:2015-07-01 08:58:24
【问题描述】:
我正在尝试使用 https 运行我的节点服务器。我正在使用 express 和 socket.io。
这是我的 https 代码:
var httpsPort = 443;
var privateKey = fs.readFileSync(mykeypath');
var certificate = fs.readFileSync(mycertificatepath');
var credentials = {key: privateKey, cert: certificate};
var https = require('https').Server(credentials,app);
var io = require('socket.io')(https);
https.listen(httpsPort, function(){
logger.info('listening on *:' + httpsPort);
});
app.get('/initGame', function (req,res){
var slots = require('./slots.json', 'utf8');
var userObject = {
address : req.connection.remoteAddress,
userAgent : req.headers['user-agent']
};
db.getPlayedGames(userObject,function(playedGames){
logger.debug(playedGames);
if(typeof playedGames == 'undefined' ){
playedGames=0;
}else{
playedGames = playedGames.games_played;
}
var spinsLeft = 10-playedGames;
res.json({
spinsLeft: spinsLeft,
slots: slots
});
});
});
在我的客户端上是:
var myServer = "//" + document.domain + ":443";
$.get( myServer + "/initGame", function(data) {
totalSpinsLeft = data.spinsLeft;
$('#trysLeft').text(totalSpinsLeft);
Seven.init(data.slots);
}).fail(function(){
setTimeout(function(){
$('#spinner2').text('Fehler bitte neu laden!');
},3000);
});
现在我的服务器上出现以下异常:
uncaughtException:缺少 PFX 或证书 + 私钥。
编辑:现在我得到了
错误请求
您的浏览器发送了一个此服务器无法理解的请求。 原因:您对启用 SSL 的服务器端口使用纯 HTTP。 请改用 HTTPS 方案访问此 URL。
【问题讨论】:
标签: node.js express https socket.io