Sto cercando di eseguire il mio server nodo con https. Sto usando express e socket.io.Come utilizzare HTTPS su Node.js utilizzando Express/Socket.io
Questo è il mio codice per 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
});
});
});
sul mio cliente proprio il seguente:
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);
});
Proprio ora im ricevendo il seguente eccezione sul mio server:
uncaughtException: Mancare PFX o certificato + chiave privata.
EDIT: adesso Im ottenendo
Bad Request
Il tuo browser ha inviato una richiesta che questo server non riusciva a capire. Motivo: si sta parlando semplicemente di HTTP a una porta del server abilitata per SSL. Usa invece lo schema HTTPS per accedere a questo URL, per favore.
Grazie ha funzionato :) – kovogel
@kovogel siete i benvenuti! – Wilson
ha funzionato anche per me, grazie mille. mi accorgo che hai cambiato (punto) Server in (punto) createServer - qualsiasi motivo per questo? Ho cambiato anche il mio e ha funzionato. – edwardsmarkf