-
Notifications
You must be signed in to change notification settings - Fork 136
/
app.js
56 lines (45 loc) · 1.13 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const logger = require('koa-logger')
const responseTime = require('koa-response-time')
const bodyParser = require('koa-bodyparser')
const ratelimit = require('koa-ratelimit')
const Router = require('koa-router')
const Koa = require('koa')
const app = new Koa()
app.use(logger())
app.use(responseTime())
app.use(bodyParser())
const ratelimitВb = new Map()
app.use(ratelimit({
driver: 'memory',
db: ratelimitВb,
duration: 1000 * 55,
errorMessage: {
ok: false,
error: {
code: 429,
message: 'Rate limit exceeded. See "Retry-After"'
}
},
id: (ctx) => ctx.ip,
headers: {
remaining: 'Rate-Limit-Remaining',
reset: 'Rate-Limit-Reset',
total: 'Rate-Limit-Total'
},
max: 20,
disableHeader: false,
whitelist: (ctx) => {
return ctx.query.botToken === process.env.BOT_TOKEN
},
blacklist: (ctx) => {
}
}))
app.use(require('./helpers').helpersApi)
const route = new Router()
const routes = require('./routes')
route.use('/*', routes.routeApi.routes())
app.use(route.routes())
const port = process.env.PORT || 3000
app.listen(port, () => {
console.log('Listening on localhost, port', port)
})