-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (35 loc) · 1.15 KB
/
index.js
File metadata and controls
39 lines (35 loc) · 1.15 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
const express = require("express");
const path = require("path");
const validasi = require("./lib/validasi");
const countryList = require("./utils/data.json");
const PORT = process.env.PORT || 3000;
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
app.get("/api/validasi", async (req, res) => {
try {
let { id, serverid } = req.query;
if (id && serverid) {
let response = await validasi(id, serverid);
return res.json({
status: "success",
result: {
nickname: response['in-game-nickname']?.replace(/\+/g, " "),
country: countryList.find(a => a.countryShortCode == response.country)?.countryName || "Unknown"
}
});
} else {
return res.sendStatus(400);
}
} catch (e) {
console.error(e)
return res.status(500).json({
status: "failed",
message: e?.message || e || "Unknown Error"
});
}
});
// Start the server
app.listen(PORT, () => {
console.log(`> Ready on http://localhost:${PORT}`);
});