Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node中间件 #32

Open
zonglang opened this issue Jul 22, 2019 · 0 comments
Open

node中间件 #32

zonglang opened this issue Jul 22, 2019 · 0 comments

Comments

@zonglang
Copy link
Owner

app.use()的原理

app.use()加载用于处理http请求的middleware(中间件),请求会一次被middlewares处理

function middleware(req, res, next) {
    // 做点什么
    // 调用下一个
    next()
}

原理就是,express维护了一个函数数组,
实现了一个next()方法,从函数数组中依次取出函数,并把next作为传参。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant