forked from detectiveHLH/koa2-response
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
35 lines (29 loc) · 734 Bytes
/
example.js
File metadata and controls
35 lines (29 loc) · 734 Bytes
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
const koa = require('koa');
const router = require('koa-router')();
const app = new koa();
const response = require('./index');
const code = {
UNKNOWN_ERROR: [1, 'Sorry, you seem to have encountered some unknown errors.']
}
app.use(response);
router
.get('/success_test', (ctx, next) => {
ctx.success({
name: 'test'
})
})
.get('/error_test', (ctx) => {
ctx.error(code.UNKNOWN_ERROR)
})
// router
// .get('/', (ctx, next) => {
// response.success(ctx, {
// name: 'test'
// })
// })
// .get('/error_test', (ctx, next) => {
// response.error(ctx, code.UNKNOWN_ERROR);
// })
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000);