Added HTTPS support
This commit is contained in:
parent
567eb5b574
commit
069cb423fd
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -2,4 +2,6 @@ node_modules/
|
|||
package-lock.json
|
||||
config.json
|
||||
state.json
|
||||
chatexamples.txt
|
||||
chatexamples.txt
|
||||
server.cert
|
||||
server.key
|
||||
|
|
@ -6,6 +6,10 @@
|
|||
"domain": "localhost",
|
||||
"sessionSecret": "CHANGE_ME",
|
||||
"altchaSecret": "CHANGE_ME",
|
||||
"ssl":{
|
||||
"cert": "./server.cert",
|
||||
"key": "./server.key"
|
||||
},
|
||||
"db":{
|
||||
"address": "127.0.0.1",
|
||||
"port": "27017",
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
});
|
||||
|
|
@ -26,7 +26,7 @@ const validator = require('validator');//We need validators for express-less cod
|
|||
|
||||
module.exports.securityCheck = function(){
|
||||
//Check Protocol
|
||||
if(config.protocol == 'http'){
|
||||
if(config.protocol.toLowerCase() != 'https'){
|
||||
//If it's insecure then warn the admin
|
||||
loggerUtil.consoleWarn("Starting in HTTP mode. This server should be used for development purposes only!");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue