-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
37 lines (30 loc) · 837 Bytes
/
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
const express=require("express")
const app=express()
const scrapInit=require("./scrapInit")
const storedata=require("./storage")
const storage=new storedata()
const rateLimit = require("express-rate-limit")
app.listen(process.env.PORT||3000,async()=>{
console.log("started")
scrapInit()
})
const apiLimiter = rateLimit({
windowMs: 1*60*1000,
max: 25,
standardHeaders:true,
legacyHeaders: false,
})
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.setHeader('Access-Control-Allow-Methods', 'GET');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next()
});
app.set('trust proxy', 5)
app.get('/',apiLimiter,async(req,res)=>{
storage.getdata().then(data=>{
res.json(data)
}).catch(err=>{
res.sendStatus(404)
})
})