根據上篇博文的博文,繼續接下來咱們實現的洋蔥圈模型的實現
新建middleware文件夾
async
//m1.js function m1(ctx){ global.console.log('m1') } module.exports = function(){ return async function(ctx,next){ global.console.log('m1 start') m1(ctx) await next() global.console.log('m1 end') } }
//m2.js function m3(ctx){ global.console.log('m3') } module.exports = function(){ return async function(ctx,next){ global.console.log('m3 start') m3(ctx) await next() global.console.log('m3 end') } }
//m3.js function m2(ctx){ global.console.log('m2') } module.exports = function(){ return async function(ctx,next){ global.console.log('m2 start') m2(ctx) await next() global.console.log('m2 end') } }
運行結果爲
3d