Add custom port support

This commit is contained in:
Myx
2024-08-27 10:51:09 +02:00
parent 5cb3b69c15
commit f9212d0aec
3 changed files with 11 additions and 2 deletions

View File

@@ -6,12 +6,15 @@ import fs from 'fs';
import bodyParser from 'body-parser';
import https from 'https';
import ip from 'ip';
import * as dotenv from 'dotenv';
import { Handlers } from "./handlers/index"
import { loadAvoidList } from '../helpers/load-avoid-list';
import { LoggerColors } from '../helpers/logger-colors';
import { generateFileName } from '../helpers/generate-file-name';
dotenv.config();
const app = express();
const storage = diskStorage({
destination: 'sounds/',
@@ -100,7 +103,7 @@ app.get('/avoidlist', (_req, res) => {
* @returns void
*/
export function startServer() {
let port: 80 | 443 = 80;
let port: number = 80;
let server;
let ssl: "https" | "http" = "http";
@@ -111,6 +114,7 @@ export function startServer() {
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";
port = 443;
@@ -120,6 +124,10 @@ export function startServer() {
ssl = "http";
}
if (process.env.WEBPORT) {
port = parseInt(process.env.WEBPORT, 10);
}
server.listen(port, () => {
console.log(`Server started at ${ssl}://${ip.address()}:${port}`);
});