-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathkoa.js
More file actions
38 lines (28 loc) · 759 Bytes
/
koa.js
File metadata and controls
38 lines (28 loc) · 759 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
36
37
38
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx, next) => {
console.log(1); // 1
await next(); // 2
console.log(2); // 8
});
app.use(async (ctx, next) => {
console.log(3); // 3
await new Promise((resolve => {
setTimeout(resolve, 300);
})); // 4
await next(); // 5
console.log(4); // 7
});
// app.use(require('./koa-error'))
// process.on('unhandledRejection', (err) => {
// console.error(`unhandledRejection: ${err.message}, stack: ${err.stack}`);
// });
// process.on('uncaughtException', (err) => {
// console.error(`uncaughtException: ${err.message}, stack: ${err.stack}`);
// });
app.use(async (ctx, next) => {
// 6
ctx.body = 'Hello World';
// throw new Error('hehe')
});
app.listen(3000);