2024-06-14 15:15:11 +00:00
|
|
|
import { Server } from "bittorrent-tracker";
|
2024-06-24 08:40:32 +00:00
|
|
|
import dotenv from "dotenv";
|
|
|
|
|
|
|
|
dotenv.config();
|
2024-06-14 14:57:55 +00:00
|
|
|
|
|
|
|
const PORT = process.env.TRACKER_PORT || 8106;
|
2024-06-14 15:15:11 +00:00
|
|
|
const HOST = process.env.TRACKER_HOST || "localhost";
|
2024-06-14 14:57:55 +00:00
|
|
|
|
2024-06-24 08:40:32 +00:00
|
|
|
const port = Number(PORT);
|
|
|
|
if (isNaN(port) || port <= 0) {
|
|
|
|
throw new Error("Invalid TRACKER_PORT value. It must be a positive number.");
|
|
|
|
}
|
|
|
|
|
2024-06-14 14:57:55 +00:00
|
|
|
const server = new Server({
|
2024-06-15 14:23:35 +00:00
|
|
|
udp: false,
|
2024-06-16 13:54:00 +00:00
|
|
|
http: false,
|
2024-06-14 14:57:55 +00:00
|
|
|
ws: true,
|
2024-06-15 14:23:35 +00:00
|
|
|
stats: false,
|
2024-06-14 14:57:55 +00:00
|
|
|
});
|
|
|
|
|
2024-06-14 15:15:11 +00:00
|
|
|
server.on("error", (err) => {
|
2024-06-14 14:57:55 +00:00
|
|
|
console.error(`Error: ${err.message}`);
|
|
|
|
});
|
|
|
|
|
2024-06-14 15:15:11 +00:00
|
|
|
server.on("warning", (err) => {
|
2024-06-14 14:57:55 +00:00
|
|
|
console.warn(`Warning: ${err.message}`);
|
|
|
|
});
|
|
|
|
|
2024-06-14 15:15:11 +00:00
|
|
|
server.on("listening", () => {
|
2024-06-24 08:40:32 +00:00
|
|
|
console.log(`Tracker is listening on ws://${HOST}:${PORT}`);
|
2024-06-14 14:57:55 +00:00
|
|
|
});
|
|
|
|
|
2024-06-24 08:40:32 +00:00
|
|
|
try {
|
|
|
|
server.listen(port, HOST, () => {
|
|
|
|
console.log(`Tracker server started on ws://${HOST}:${PORT}`);
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(`Failed to start tracker server: ${err.message}`);
|
|
|
|
}
|