forked from PrivateCoffee/transfer.coffee
Kumi
2394a9f6ee
- Added `helmet` middleware for enhanced security with CSP. - Integrated `dotenv` for configuration management. - Added validation and error handling for mnemonic and infoHash. - Improved error handling in TURN credentials generation. - Enhanced notification and progress feedback for file sharing. - Added tracker server config validation and error handling. - Updated dependencies to include `helmet` and `dotenv`. These changes improve the app's security, robustness, and user experience.
39 lines
No EOL
882 B
JavaScript
39 lines
No EOL
882 B
JavaScript
import { Server } from "bittorrent-tracker";
|
|
import dotenv from "dotenv";
|
|
|
|
dotenv.config();
|
|
|
|
const PORT = process.env.TRACKER_PORT || 8106;
|
|
const HOST = process.env.TRACKER_HOST || "localhost";
|
|
|
|
const port = Number(PORT);
|
|
if (isNaN(port) || port <= 0) {
|
|
throw new Error("Invalid TRACKER_PORT value. It must be a positive number.");
|
|
}
|
|
|
|
const server = new Server({
|
|
udp: false,
|
|
http: false,
|
|
ws: true,
|
|
stats: false,
|
|
});
|
|
|
|
server.on("error", (err) => {
|
|
console.error(`Error: ${err.message}`);
|
|
});
|
|
|
|
server.on("warning", (err) => {
|
|
console.warn(`Warning: ${err.message}`);
|
|
});
|
|
|
|
server.on("listening", () => {
|
|
console.log(`Tracker is listening on ws://${HOST}:${PORT}`);
|
|
});
|
|
|
|
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}`);
|
|
} |