-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (32 loc) · 880 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import express from "express";
import cors from "cors";
import { downloadVideo } from "tiktok-api-downloader";
const app = express();
const PORT = process.env.PORT || 4000;
app.use(cors());
app.get("/", (req, res) => {
return res.status(200).json({
status: true,
error:
"GET /download This endpoint retrieves download URLs for a TikTok video.",
});
});
app.get("/download", async (req, res) => {
const url = req.query.url;
if (!url) {
return res.status(400).json({ status: false, error: "URL is required" });
}
try {
let response = await downloadVideo(url);
return res.status(200).json(response);
} catch (error) {
console.error(error);
return res.status(500).json({
status: false,
error: "Failed to download video",
});
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});