-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathapp.js
66 lines (57 loc) · 1.54 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
57
58
59
60
61
62
63
64
65
66
const logger = require('koa-logger')
const responseTime = require('koa-response-time')
const bodyParser = require('koa-bodyparser')
const ratelimit = require('koa-ratelimit')
const port = process.env.PORT || 3000
const Router = require('koa-router')
const fetch = require('node-fetch')
const ratelimitВb = new Map()
const Koa = require('koa')
const app = new Koa()
app.use(logger())
app.use(responseTime())
app.use(bodyParser())
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 === global.botToken
},
blacklist: (ctx) => {
}
}))
app.use(require('./helpers').helpersApi)
const route = new Router()
const routes = require('./routes')
route.get('/', (ctx, next) => {
ctx.body = "Server Quoted Chat Online, Please Read Docs Here https://github.com/rizzlogy/qc-api";
})
route.use('/*', routes.routeApi.routes())
app.use(route.routes())
app.listen(port, () => {
console.log('Listening on localhost, port', port)
keepAlive()
})
function keepAlive() {
const url = `https://${process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`
if (/(\/\/|\.)undefined\./.test(url)) return
setInterval(()=> {
fetch(url).catch(console.error)
}, 5 * 1000 * 60)
}