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}`);
});

View File

@@ -4,7 +4,7 @@
"description": "Discord bot randomly plays sounds",
"scripts": {
"start": "ts-node bot.ts",
"create": "node -e \"require('fs').writeFileSync('.env', 'TOKEN=MY-API-TOKEN\\nINTERVALMIN_MINUTES=10\\nINTERVALMAX_HOURS=6\\nVOICECHANNELRETRIES=12')\"",
"create": "node -e \"require('fs').writeFileSync('.env', 'TOKEN=MY-API-TOKEN\\nINTERVALMIN_MINUTES=10\\nINTERVALMAX_HOURS=6\\nVOICECHANNELRETRIES=12')\" && mkdir sounds",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "SocksOnHead",

View File

@@ -32,6 +32,7 @@ TOKEN=<your Discord bot token>
INTERVALMIN_MINUTES=<minimum interval in minutes>
INTERVALMAX_HOURS=<maximum interval in hours>
VOICECHANNELRETRIES=<number of retries to find a voice channel with members in it>
WEBPORT=<The port you want to use for the webserver, (Optional)>
```
replace `<your Discord bot token>` with your actual Discord bot token. replace `<minimum interval in minutes>`, `<maximum interval in hours>`, and `<number of retries to find a voice channel with members in it>` with your desired values.