Im trying to run my node server with https. I'm using express and socket.io.
This is my code for 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
});
});
});
on my client its the following:
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);
});
Right now im getting the following exception on my server:
uncaughtException: Missing PFX or certificate + private key.
EDIT: right now im getting
Bad Request
Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.