routers.js
2.4 KB
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
'use strict';
const Router = require('koa-router');
const common = require('./actions/common');
const index = require('./actions/index');
const projects = require('./actions/projects');
const servers = require('./actions/servers');
const login = require('./actions/login');
const monitor = require('./actions/monitor');
const users = require('./actions/users');
const hotfix = require( './actions/hotfix');
const operationLog = require('./actions/operation_log');
const pageCache = require( './actions/page_cache');
const cdnCache = require( './actions/cdn_cache');
const productCache = require( './actions/product_cache');
const apiCache = require('./actions/api_cache');
const degrade = require('./actions/degrade');
const deploy = require('./actions/deploy');
const api = require('./actions/api');
const abuseProtection = require('./actions/abuse_protection');
const noAuth = new Router();
const base = new Router();
module.exports = function (app) {
noAuth.use('', login.routes(), login.allowedMethods());
noAuth.use('', common.routes(), common.allowedMethods());
noAuth.use('/api', api.routes(), api.allowedMethods());
app.use(noAuth.routes(), noAuth.allowedMethods());
app.use(async (ctx, next) => {
if (ctx.session && ctx.session.user) {
await next();
} else {
ctx.redirect('/login');
}
});
base.use('/projects', projects.routes(), projects.allowedMethods());
base.use('/servers', servers.routes(), servers.allowedMethods());
base.use('/monitor', monitor.routes(), monitor.allowedMethods());
base.use('/users', users.routes(), users.allowedMethods());
// base.use('/hotfix', hotfix.routes(), hotfix.allowedMethods());
base.use('/operation', operationLog.routes(), operationLog.allowedMethods());
base.use('/page_cache', pageCache.routes(), pageCache.allowedMethods());
base.use('/cdn_cache', cdnCache.routes(), cdnCache.allowedMethods());
base.use('/product_cache', productCache.routes(), productCache.allowedMethods());
base.use('/api_cache', apiCache.routes(), apiCache.allowedMethods());
base.use('/degrade', degrade.routes(), degrade.allowedMethods());
base.use('/deploys', deploy.routes(), deploy.allowedMethods());
base.use('/abuse_protection', abuseProtection.routes(), degrade.allowedMethods());
base.use('', index.routes(), index.allowedMethods());
app.use(base.routes(), base.allowedMethods());
}