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

why serve-static did not call next() method like other middleware #68

Closed
kimown opened this issue Jul 9, 2016 · 1 comment
Closed
Assignees
Labels

Comments

@kimown
Copy link

kimown commented Jul 9, 2016

I want to modify the response body after I use the serve-static middleware , but I am very confused why serve-static only call next() when error happens, I saw other middleware's code ,like compression,cookie-session ,finally they all call next() method.

@dougwilson dougwilson self-assigned this Jul 9, 2016
@dougwilson
Copy link
Contributor

Hi @kimown, the reason this module does not call next() unless it's an error is because in Express and the middleware pattern, you only call next() if you either (a) encountered an error or (b) did not write out a response body.

Since this module writes out a response body, it does not call next(), as this module already handled the request by sending a response. All the other examples you gave (compression and cookie-session) are not sending a response back, thus they are calling next() in the non-error case.

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

No branches or pull requests

2 participants