-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (41 loc) · 1.46 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
import express from 'express';
import dotenv from 'dotenv';
import fetch from 'node-fetch';
import path from 'path';
import { fileURLToPath } from 'url';
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static('public'));
app.get('/api/characters', async (req, res) => {
try {
const response = await fetch(`https://api.nexalo.xyz/free-fire?list&api=${process.env.API_KEY}`);
const data = await response.json();
res.json(data);
} catch (error) {
res.status(500).json({ error: 'An error occurred while fetching characters' });
}
});
app.get('/api/character/:name', async (req, res) => {
try {
const response = await fetch(`https://api.nexalo.xyz/free-fire?info=${req.params.name}&api=${process.env.API_KEY}`);
const data = await response.json();
res.json(data);
} catch (error) {
res.status(500).json({ error: 'An error occurred while fetching character info' });
}
});
app.get('/api/search/:query', async (req, res) => {
try {
const response = await fetch(`https://api.nexalo.xyz/free-fire?q=${req.params.query}&api=${process.env.API_KEY}`);
const data = await response.json();
res.json(data);
} catch (error) {
res.status(500).json({ error: 'An error occurred while searching characters' });
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});