-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (39 loc) · 1.08 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
const Koa = require('koa');
const InitManager = require('./core/init');
const parser = require('koa-bodyparser');
const cors = require('@koa/cors');
// const ratelimit = require('koa-ratelimit');
require('module-alias/register');
const app = new Koa();
app.use(cors())
// app.use(catchError)
app.use(parser())
// 接口调用频率限制(Rate-Limiting)
// Rate limiter middleware for koa.
// https://github.com/koajs/ratelimit
// const db = new Map()
// app.use(ratelimit({
// driver: 'memory',
// db: db,
// duration: 60000,
// errorMessage: 'Sometimes You Just Have to Slow Down.',
// id: (ctx) => ctx.ip,
// headers: {
// remaining: 'Rate-Limit-Remaining',
// reset: 'Rate-Limit-Reset',
// total: 'Rate-Limit-Total'
// },
// max: 100,
// disableHeader: false,
// whitelist: (ctx) => {
// // some logic that returns a boolean
// },
// blacklist: (ctx) => {
// // some logic that returns a boolean
// }
// }))
InitManager.initCore(app)
app.listen(8000, () => {
console.log('Koa is listening in http://localhost:8000')
})
module.exports = app