Reaperxxxx commited on
Commit
c6e5396
Β·
verified Β·
1 Parent(s): 23bf3a9

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +5 -3
server.js CHANGED
@@ -6,7 +6,6 @@ const https = require("https");
6
 
7
  const app = express();
8
  const PORT = 7860;
9
- const HOST_URL = "https://your-domain.com"; // πŸ”Ή Replace with your actual domain
10
  const DOWNLOAD_DIR = path.join(__dirname, "downloads");
11
 
12
  // Ensure the downloads directory exists
@@ -74,7 +73,10 @@ app.get("/download", async (req, res) => {
74
  response.data.pipe(writer);
75
 
76
  writer.on("finish", () => {
77
- const servedUrl = `${HOST_URL}/files/${filename}`;
 
 
 
78
  scheduleFileDeletion(filePath); // Auto-delete after 10 minutes
79
  console.log(`βœ… Download complete: ${servedUrl}`);
80
  return res.json({ message: "Download complete", fileUrl: servedUrl });
@@ -96,5 +98,5 @@ app.use("/files", express.static(DOWNLOAD_DIR));
96
 
97
  // Start the server
98
  app.listen(PORT, () => {
99
- console.log(`πŸš€ Server running on ${HOST_URL}:${PORT}`);
100
  });
 
6
 
7
  const app = express();
8
  const PORT = 7860;
 
9
  const DOWNLOAD_DIR = path.join(__dirname, "downloads");
10
 
11
  // Ensure the downloads directory exists
 
73
  response.data.pipe(writer);
74
 
75
  writer.on("finish", () => {
76
+ // Dynamically get the host URL from request headers
77
+ const hostUrl = `${req.protocol}://${req.get("host")}`;
78
+ const servedUrl = `${hostUrl}/files/${filename}`;
79
+
80
  scheduleFileDeletion(filePath); // Auto-delete after 10 minutes
81
  console.log(`βœ… Download complete: ${servedUrl}`);
82
  return res.json({ message: "Download complete", fileUrl: servedUrl });
 
98
 
99
  // Start the server
100
  app.listen(PORT, () => {
101
+ console.log(`πŸš€ Server running on port ${PORT}`);
102
  });