You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consthttp=require('http')functioncompose(middlewareList){returnfunction(ctx){functiondispatch(i){constfn=middlewareList[i]try{returnPromise.resolve(fn(ctx,dispatch.bind(null,i+1)))}catch(err){Promise.reject(err)}}returndispatch(0)}}classApp{constructor(){this.middlewares=[]}use(fn){this.middlewares.push(fn)returnthis}handleRequest(ctx,middleware){returnmiddleware(ctx)}createContext(req,res){constctx={
req,
res
}returnctx}callback(){constfn=compose(this.middlewares)return(req,res)=>{constctx=this.createContext(req,res)returnthis.handleRequest(ctx,fn)}}listen(...args){constserver=http.createServer(this.callback())returnserver.listen(...args)}}module.exports=App
欢迎在下方发表您的优质见解
The text was updated successfully, but these errors were encountered: