From b4d46c4cdd40206ddf4c795e1c217aa4799e0063 Mon Sep 17 00:00:00 2001 From: idk-pixel <63606830+idk-pixel@users.noreply.github.com> Date: Fri, 17 Dec 2021 18:07:40 -0600 Subject: [PATCH 1/2] Support SSL --- config-example.json | 7 +++++++ src/structures/app.js | 24 ++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/config-example.json b/config-example.json index 90ec2c10..a8500219 100644 --- a/config-example.json +++ b/config-example.json @@ -37,5 +37,12 @@ "site_key": "", "secret_key": "" } + }, + "ssl": { + "enabled": false, + "cert_path": "../ssl/ilikehttps.cert", + "ca_path": "../ssl/ilikehttps.ca-bundle", + "key_path": "../ssl/ilikehttps.key", + "domain_name_without_protocol": "ilikehttps.com" } } diff --git a/src/structures/app.js b/src/structures/app.js index 3225cf2a..a8ac318a 100644 --- a/src/structures/app.js +++ b/src/structures/app.js @@ -4,7 +4,7 @@ const cookieParser = require("cookie-parser"); const session = require("express-session"); const passport = require("passport"); -const { discord_client: {secret} } = require("@root/config.json"); +const { discord_client: {secret}, ssl } = require("@root/config.json"); require("@utils/passport.js"); @@ -40,7 +40,27 @@ class App { } listen(port) { - return new Promise((resolve) => this.express.listen(port, resolve)); + const fs = require('fs'); + // return new Promise((resolve) => this.express.listen(port, resolve)); + if(ssl.enabled === true) { + let httpsOptions = { + cert: ssl.cert_path, + ca: ssl.ca_path, + key: ssl.key_path + } + return new Promise((resolve) => { + const https = require('https'); + const httpsServer = https.createServer(httpsOptions, this.express); + // Encoding port 443 since it is SSL. + httpsServer.listen(443, ssl.domain_name_without_protocol); + resolve(); + // SSL Should now be online! + }) + } else if(ssl.enabled === false){ + return new Promise((resolve) => this.express.listen(port, resolve)); + } else { + return console.log('Invalid SSL Enabled/Disabled input') + } } loadRoutes() { From b79d812b37259fa147acaedf91d3daeeab0714ad Mon Sep 17 00:00:00 2001 From: idk-pixel <63606830+idk-pixel@users.noreply.github.com> Date: Sat, 18 Dec 2021 12:23:53 -0600 Subject: [PATCH 2/2] Required Modules & Read the SSL Files --- src/structures/app.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/structures/app.js b/src/structures/app.js index a8ac318a..fef82f0a 100644 --- a/src/structures/app.js +++ b/src/structures/app.js @@ -43,10 +43,11 @@ class App { const fs = require('fs'); // return new Promise((resolve) => this.express.listen(port, resolve)); if(ssl.enabled === true) { + const path = require('path'); let httpsOptions = { - cert: ssl.cert_path, - ca: ssl.ca_path, - key: ssl.key_path + cert: fs.readFileSync(path.join(__dirname, ssl.cert_path)), + ca: fs.readFileSync(path.join(__dirname,ssl.ca_path)), + key: fs.readFileSync(path.join(__dirname, ssl.key_path)) } return new Promise((resolve) => { const https = require('https');