两者无论写法,还是执行顺序,也没啥区别啊,区别是啥???
var app = require('express')();
app.use(function myMiddleware(req, res, next) {
res.write('Hello world.');
next();
});
app.use(function mySecondMiddleware(req, res) {
res.write('\nI am a second middleware.');
res.end();
});
var app = require('koa')();
app.use(function* myMiddleware(next) {
this.response.body = 'Hello world.';
yield next;
});
app.use(function* mySecondMiddleware() {
this.response.body += '\nI am a second middleware.';
});