Added HTTPS support
This commit is contained in:
parent
567eb5b574
commit
069cb423fd
4 changed files with 35 additions and 9 deletions
|
|
@ -14,6 +14,13 @@ GNU Affero General Public License for more details.
|
|||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//Define global crypto variable for altcha
|
||||
globalThis.crypto = require('node:crypto').webcrypto;
|
||||
|
||||
//Define NODE imports
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
|
||||
//Define NPM imports
|
||||
const express = require('express');
|
||||
const session = require('express-session');
|
||||
|
|
@ -23,9 +30,6 @@ const path = require('path');
|
|||
const mongoStore = require('connect-mongo');
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
//Define global crypto variable for altcha
|
||||
globalThis.crypto = require('node:crypto').webcrypto;
|
||||
|
||||
//Define Local Imports
|
||||
//Application
|
||||
const channelManager = require('./app/channel/channelManager');
|
||||
|
|
@ -82,9 +86,25 @@ const sessionMiddleware = session({
|
|||
store: module.exports.store
|
||||
});
|
||||
|
||||
//Define http and socket.io servers
|
||||
const httpServer = createServer(app);
|
||||
const io = new Server(httpServer, {});
|
||||
//Declare web server
|
||||
let webServer = null;
|
||||
|
||||
//If we're using HTTPS
|
||||
if(config.protocol.toLowerCase() == "https"){
|
||||
//Read key/cert files and store contents
|
||||
const httpsOptions = {
|
||||
key: fs.readFileSync(config.ssl.key),
|
||||
cert: fs.readFileSync(config.ssl.cert)
|
||||
};
|
||||
|
||||
webServer = https.createServer(httpsOptions, app);
|
||||
|
||||
//Otherwise
|
||||
}else{
|
||||
//Default to HTTP
|
||||
webServer = createServer(app)
|
||||
}
|
||||
const io = new Server(webServer, {});
|
||||
|
||||
//Connect mongoose to the database
|
||||
mongoose.set("sanitizeFilter", true).connect(dbUrl).then(() => {
|
||||
|
|
@ -164,6 +184,6 @@ scheduler.kickoff();
|
|||
module.exports.channelManager = new channelManager(io)
|
||||
|
||||
//Listen Function
|
||||
httpServer.listen(port, () => {
|
||||
webServer.listen(port, () => {
|
||||
console.log(`Opening port ${port}`);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue