mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-07-08 22:15:09 +00:00
Added ssl support
This commit is contained in:
13
client/certs/create-cert.sh
Normal file
13
client/certs/create-cert.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Generate a private key
|
||||
openssl genrsa -out key.pem 2048
|
||||
|
||||
# Generate a CSR using the private key
|
||||
openssl req -new -key key.pem -out csr.pem
|
||||
|
||||
# Generate a certificate using the private key and CSR
|
||||
openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out cert.pem
|
||||
|
||||
# Delete the CSR, we don't need it anymore
|
||||
rm csr.pem
|
||||
@@ -7,6 +7,8 @@ import ytdl from 'ytdl-core';
|
||||
import fs from 'fs';
|
||||
import bodyParser from 'body-parser';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import https from 'https';
|
||||
import ip from 'ip';
|
||||
|
||||
const app = express();
|
||||
const storage = diskStorage({
|
||||
@@ -121,7 +123,25 @@ app.use(express.static(path.join(__dirname, "web")));
|
||||
|
||||
export function startServer() {
|
||||
const port = 8080;
|
||||
app.listen(port, () => {
|
||||
console.log(LoggerColors.Cyan,`Add sounds at http://localhost:${port}, or drop in the sounds folder.`);
|
||||
let server;
|
||||
let ssl: "https" | "http" = "http";
|
||||
|
||||
try {
|
||||
const options = {
|
||||
requestCert: true,
|
||||
rejectUnauthorized: false,
|
||||
key: fs.readFileSync(path.join(__dirname, '/certs/key.pem')),
|
||||
cert: fs.readFileSync(path.join(__dirname, '/certs/cert.pem')),
|
||||
};
|
||||
server = https.createServer(options, app);
|
||||
ssl = "https";
|
||||
} catch (error) {
|
||||
console.log(LoggerColors.Yellow, 'Could not find SSL certificates, falling back to http.');
|
||||
server = app;
|
||||
ssl = "http";
|
||||
}
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`Server started at ${ssl}://${ip.address()}:${port}`);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user