Files
  • index.js
  • package-lock.json
  • package.json
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
const express = require('express');
const axios = require('axios')
var pretty = require('express-prettify');
var jsonstore = require('jsonstore.io')


const app = express();
app.use(express.static('public'));
app.use(pretty({ query: 'pretty' }));

let store = new jsonstore(process.env.DB)


app.get('/', (req, res) => {
  res.send(`yo it's all at /fetch`)
});

app.get('/fetch', (req, res) => {
  var inToken = req.query.token
  store.read(inToken).then( (data) => {
    if((data<1000)){
      req.query.token = process.env.TOKEN;
      var queryString = Object.keys(req.query).map(key => key + '=' + req.query[key]).join('&');
      axios.get(`https://page.rest/fetch?${queryString}`)
      .then(function (response) {
        res.send(response.data);
      })
      .catch(function (error) {
        res.send(`something went wrong`)
      });
      store.write(inToken, data+1)
    }
    else{
      res.send(`bruh what`)
    }
  })
});

app.listen(3000, () => console.log('server started'));