i deploy a simple nodejs server on heroku with ssl valid certificate
var https = require('https');
var express = require('express');
var bodyParser = require('body-parser');
var fs = require('fs');
var app = express();
var cors = require('cors');
var credentials = {
key: fs.readFileSync('./cert/key.key'),
cert: fs.readFileSync('./cert/cert.crt'),
ca: fs.readFileSync('./cert/bundle.crt'),
requestCert: true,
rejectUnauthorized: false
};
var server = https.createServer(credentials, app);
var io = require('socket.io')(server);
app.use(cors());
app.use(bodyParser.json({limit: '12mb'}));
app.use(bodyParser.urlencoded({limit: '12mb', extended: true }));
io.on('connection', function(socket){
console.log(socket);
socket.on('authenticate', function(data){
console.log(data);
});
});
var port = process.env.PORT || 8080;
server.listen(port, function () {
console.log("server listen on", this.address());
});
server.on('clientError', function(err) {
console.log('ERROR', err);
});
the problem is that when i start the app i received this error
ERROR { Error: socket hang up
at TLSSocket.<anonymous> (_tls_wrap.js:820:25)
at emitOne (events.js:101:20)
at TLSSocket.emit (events.js:188:7)
at Socket._handle.close (net.js:492:12)
at Socket.g (events.js:286:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:492:12) code: 'ECONNRESET' }
when i try to connect by chrome to my server i received this error in server side
2017-01-05T15:03:43.465542+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/socket.io/?EIO=3&transport=polling&t=LblA3JZ" host=www.myapp.com request_id=51982ce9-99e3-4677-acb4-a0f14eb88999 fwd="95.251.90.218" dyno=web.1 connect=1ms service=2ms status=503 bytes=0
2017-01-05T15:03:43.460178+00:00 app[web.1]: ERROR Error: 140414443095936:error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request:../deps/openssl/openssl/ssl/s23_srvr.c:394:
and this error in the client side
XMLHttpRequest cannot load https://www.myapp.com/socket.io/?EIO=3&transport=polling&t=LblDK25. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.8:8100' is therefore not allowed access. The response had HTTP status code 503.
at first moment i thought that was socket.io but the problem persist also with normal REST operation. now i think that i a SSL problem. i create a valid certificate with godaddy provider and i upload it to heroku with success. in fact if i try to connect to my app through https connection the certificate is valid. maybe the problem is when i try to upload this certificates into my nodejs app.someone can help me? thanks in advance