I created a Node.js chat application with Socket.io. It worked well on local. Then I deployed on my Azure website with SSL certificate, I got error. Can you guy help me?
This is my code:
Server.js:
debugger;
const connect = require('connect');
const fs = require('fs');
const options = {
key: fs.readFileSync('./www.reic.vn.key'),
cert: fs.readFileSync('./www.reic.vn.crt'),
ca: fs.readFileSync('./bundle.crt'),
requestCert: false,
rejectUnauthorized: false
};
onst express = require("express");
const http = require('https');//.createServer(options);
const socketio = require('socket.io');
const bodyParser = require('body-parser');
const routes = require('./utils/routes');
const config = require('./utils/config');
const mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1:27017/chat');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('we are connected!');
});
var chatSchema = mongoose.Schema({
From:String,
Message:String,
To:String,
FromIdWeb: String,
ToIdWeb: String,
FromImgWeb: String,
ToImgWeb:String,
IsReaded: {type:String,default:'1'},
CreatedDate:{type:Date,default:Date.now}
});
var Chat = mongoose.model('Message',chatSchema);
//
class Server{
constructor(){
//this.port = process.env.PORT || 3000;
this.port = process.env.HTTPS_PORT||3000;
this.host = `127.0.0.1`;
this.app = express();
//this.https = https.Server(options.this.app);
this.http = http.Server(options,this.app);
//this.http = http.Server(this.app);
this.socket = socketio(this.http);
}
appConfig(){
this.app.use(
bodyParser.json()
);
new config(this.app);
}
/* Including app Routes starts*/
includeRoutes(){
new routes(this.app,this.socket).routesConfig();
}
/* Including app Routes ends*/
appExecute(){
debugger;
this.appConfig();
this.includeRoutes();
this.http.listen(this.port, this.host, () => {
console.log(`Listening on http://${this.host}:${this.port}`);
});
}
}
const app = new Server();
app.appExecute();
The port 3000 was created in Azure application setting.
I am using Comodo EssentialSSL certificate. I generated Comodo Certificate file into .gem and .key using OPENSSL-Win32.
This is the result wwhen I run command node sever.js:
And this error messsage from client computer:
Firefox can’t establish a connection to the server at wss://www.reic.vn/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=SbXYLozbTo28Waa4k6r1fueDrvVEmjTozpydvGbJQqTXSiNdEiSr03svJNXa2D8gp1UwYUt85axpXvcdIn4Lkr7GBjP%2FUYN4%2BmEyu5nO7%2FtwC4SJHuV%2F8LjYzbCs1oJ97MMFKEYLo7kP4eHATVBBtw%3D%3D&connectionData=%5B%7B%22name%22%3A%22hubs%22%7D%5D&tid=10.
Hope you guys can help. Thank you!
via Kiva Dang
No comments:
Post a Comment