fast72 commited on
Commit
87d65df
·
verified ·
1 Parent(s): 6e10134

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +16 -26
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
- const baseUrl = 'https://www.growagardenvalues.com/stock/refresh_stock.php?type='
8
-
9
- async function fetchStock(type) {
10
  try {
11
- const res = await axios.get(`${baseUrl}${type}`)
12
- const raw = res.data?.data?.records || []
13
- return raw.filter(r => r?.Data?.Name && typeof r.Amount === 'number')
 
 
 
 
 
 
14
  } catch {
15
- return []
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}`));