Update server.js
Browse files
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 |
-
|
|
|
|
|
|
|
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 ${
|
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 |
});
|