【发布时间】:2021-01-18 12:49:31
【问题描述】:
我已经定义了 SSL 证书的选项,但我不知道如何在代码中使用它。所以我没有通过 HTTPS URL 获得正确的结果。 这是我的代码:
'use strict';
const express = require('express');
const https = require('https'), fs = require("fs");
const socketio = require('socket.io');
const socketEvents = require('./utils/socket');
const options = {
key: fs.readFileSync("/www/wwwroot/securechat.online/nodejs/ssl/privatekey.pem"),
cert: fs.readFileSync("/www/wwwroot/securechat.online/nodejs/ssl/cert1.pem")
};
class Server {
constructor() {
this.port = process.env.PORT || 8099;
this.host = process.env.HOST || 'securechat.online';
this.app = express();
this.https = https.Server(this.app);
this.socket = socketio(this.https);
}
appRun(){
new socketEvents(this.socket).socketConfig();
this.app.use(express.static(__dirname + '/uploads'));
this.https.listen(this.port, this.host, () => {
console.log(`Listening on https://${this.host}:${this.port}`);
});
}
}
const app = new Server();
app.appRun();
【问题讨论】: