Update index.js
Browse files
index.js
CHANGED
|
@@ -1,32 +1,22 @@
|
|
| 1 |
-
const express = require('express')
|
| 2 |
-
const axios = require('axios')
|
| 3 |
|
| 4 |
-
const app = express()
|
| 5 |
-
const PORT = 7860
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
async function fetchStock(type) {
|
| 10 |
try {
|
| 11 |
-
const
|
| 12 |
-
const
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
} catch {
|
| 15 |
-
|
| 16 |
}
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
app.get('/', async (_, res) => {
|
| 20 |
-
const [seedsRaw, gearsRaw, eggsRaw] = await Promise.all([
|
| 21 |
-
fetchStock('seeds'),
|
| 22 |
-
fetchStock('gears'),
|
| 23 |
-
fetchStock('eggs')
|
| 24 |
-
])
|
| 25 |
-
|
| 26 |
-
res.setHeader('Content-Type', 'application/json')
|
| 27 |
-
res.send(JSON.stringify({ seedsRaw, gearsRaw, eggsRaw }, null, 2))
|
| 28 |
-
})
|
| 29 |
|
| 30 |
-
app.listen(PORT, () => {
|
| 31 |
-
console.log(`http://localhost:${PORT}`)
|
| 32 |
-
})
|
|
|
|
| 1 |
+
const express = require('express');
|
|
|
|
| 2 |
|
| 3 |
+
const app = express();
|
| 4 |
+
const PORT = 7860;
|
| 5 |
|
| 6 |
+
app.all('*', async (_, res) => {
|
|
|
|
|
|
|
| 7 |
try {
|
| 8 |
+
const r = await fetch('https://growtopiagame.com/detail');
|
| 9 |
+
const json = await r.json();
|
| 10 |
+
const online = json.online_user;
|
| 11 |
+
|
| 12 |
+
if (typeof online === 'number' || /^\d+$/.test(online)) {
|
| 13 |
+
res.send(`Server is up | ${online} Players online!`);
|
| 14 |
+
} else {
|
| 15 |
+
res.send('Server is down');
|
| 16 |
+
}
|
| 17 |
} catch {
|
| 18 |
+
res.send('Server is down');
|
| 19 |
}
|
| 20 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
|
|
|
|
|
|