forked from easy-mock/easy-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router-config.js
67 lines (58 loc) · 1.84 KB
/
router-config.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
67
'use strict'
const config = require('config')
const Router = require('koa-router')
const restc = require('restc').koa2()
const ratelimit = require('koa-ratelimit')
const {
user,
mock,
util,
group,
project,
dashboard
} = require('./controllers')
const baseUtil = require('./util')
const middleware = require('./middlewares')
const rateLimitConf = config.get('rateLimit')
const apiRouter = new Router({ prefix: '/api' })
const mockRouter = new Router({ prefix: '/mock' })
const rate = ratelimit({
db: baseUtil.getRedis(),
id: ctx => ctx.url,
max: rateLimitConf.max,
duration: rateLimitConf.duration,
errorMessage: 'Sometimes You Just Have to Slow Down.',
headers: {
remaining: 'Rate-Limit-Remaining',
reset: 'Rate-Limit-Reset',
total: 'Rate-Limit-Total'
}
})
exports.mock = mockRouter
.all('*', middleware.mockFilter, rate, restc, mock.getMockAPI)
exports.api = apiRouter
.get('/wallpaper', util.wallpaper)
.post('/upload', util.upload)
.get('/dashboard', dashboard.list)
.get('/u', user.list)
.post('/u/login', user.login)
.post('/u/update', user.update)
.post('/u/register', user.register)
.get('/group', group.list)
.post('/group/join', group.join)
.post('/group/create', group.create)
.post('/group/delete', group.delete)
.post('/group/update', group.update)
.get('/project', project.list)
.post('/project/copy', project.copy)
.post('/project/create', project.create)
.post('/project/update', project.update)
.post('/project/delete', project.delete)
.post('/project/sync/swagger', project.syncSwagger)
.post('/project/update_workbench', project.updateWorkbench)
.get('/mock', mock.list)
.get('/mock/by_projects', mock.getAPIByProjectIds)
.post('/mock/create', mock.create)
.post('/mock/update', mock.update)
.post('/mock/delete', mock.delete)
.post('/mock/export', mock.exportAPI)