-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (44 loc) · 1.53 KB
/
Copy pathindex.js
File metadata and controls
51 lines (44 loc) · 1.53 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import cors from 'cors';
import express from 'express';
import fetch from 'node-fetch';
const app = express();
const port = 3000;
const apiUrl = "https://your-shoti-api.vercel.app/api/v1/get";
const apiKey = "$shoti-1hkarq1k2u7agqq6i0o";
app.use(cors());
app.get("/getRandomVideo", async (req, res) => {
try {
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ apikey: apiKey }),
});
if (!response.ok) {
const errorResponse = await response.json();
console.error(`Request failed with status ${response.status}`, errorResponse);
res.status(response.status).json(errorResponse);
} else {
const data = await response.json();
console.log("Response from Shoti API:", data);
if (data && data.code !== undefined) {
if (data.error) {
console.error("Shoti API returned an error:", data.error);
res.status(500).json({ error: data.error });
} else {
res.json(data);
}
} else {
console.error("Shoti API response is missing the 'code' property.");
res.status(500).json({ error: "Shoti API response is missing the 'code' property." });
}
}
} catch (error) {
console.error("Error fetching the random video:", error.message);
res.status(500).json({ error: "Error fetching the random Shoti video. Please try again later." });
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});