mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
Initial release
This commit is contained in:
commit
8d9b8d5627
27 files changed
+8140
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import path from "node:path";
|
||||
import { existsSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { loadConfig, saveConfig } from "./config.js";
|
||||
import { createLogger } from "./logger.js";
|
||||
import { createWebServer } from "./server/server.js";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT_DIR = path.resolve(__dirname, "..");
|
||||
const CONFIG_PATH = path.join(ROOT_DIR, "config.json");
|
||||
const CERT_DIR = path.join(ROOT_DIR, "certs");
|
||||
const DATA_DIR = path.join(ROOT_DIR, "data");
|
||||
const LOG_DIR = path.join(DATA_DIR, "logs");
|
||||
const STATIC_DIR = path.join(ROOT_DIR, "web", "dist");
|
||||
|
||||
async function main() {
|
||||
const config = loadConfig(CONFIG_PATH);
|
||||
saveConfig(CONFIG_PATH, config);
|
||||
|
||||
const logger = createLogger(LOG_DIR);
|
||||
|
||||
logger.info({ config }, "Starting WebSpeak server");
|
||||
|
||||
const hasCert = existsSync(path.join(CERT_DIR, "cert.pem"));
|
||||
|
||||
const webServer = createWebServer({
|
||||
port: config.port,
|
||||
trustProxy: config.trustProxy,
|
||||
staticDir: STATIC_DIR,
|
||||
certDir: hasCert ? CERT_DIR : undefined,
|
||||
voiceBridgeOptions: {
|
||||
tsHost: config.tsHost,
|
||||
tsPort: config.tsPort,
|
||||
tsServerPassword: config.tsServerPassword,
|
||||
tsServerProtocol: config.tsServerProtocol,
|
||||
maxClients: config.maxClients,
|
||||
},
|
||||
logger,
|
||||
});
|
||||
|
||||
await webServer.start();
|
||||
|
||||
// Graceful shutdown
|
||||
const shutdown = async (signal: string) => {
|
||||
logger.info({ signal }, "Shutting down");
|
||||
await webServer.stop();
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGINT", () => shutdown("SIGINT"));
|
||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("Fatal error:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user