-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Does parse-server call next() or not? #4085
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
Comments
Parse Server uses it's own little promise-based router which is built on top of Express' own routing engine. This is the function that eventually resolves all internal Parse Server routes: parse-server/src/PromiseRouter.js Lines 140 to 196 in 92d51de
As far as I understand it (which is pretty well since I borrowed this pattern for an app I'm working on), every internal route resolves to this handler function. It always creates a response, whether it be text, redirect, or JSON. I'm not an expert on Parse Server, but as far as I can tell the answer to your question is "No, Parse Server does not call next()." At least not on anything that passes through the Promise Router. I could be wrong, though. It's a big code-base and I haven't been through the whole thing. |
One small correction... I guess. If it's an error, next is called with the error. But if there's a successful response, any middleware you add after Parse will be skipped. |
Looks like calling next() was introduced in 2.2.17 with #2338 and reverted in 2.2.10 with #2634. Please see comments in the revert for more info but issues #2362 and #2580 are cited. I believe there is a workaround mentioned in another issue by wrapping the parse mount in your own middleware that can then implement logic before and after the parse logic. |
Ah yes, I weighed in on the surprise behavior change on #2362 (#2362 (comment)) myself — though the suggested fix (#2362 (comment)) to halt execution and maintain 2.2.16 behavior worked great. Since it's billed as "middleware", it really ought to pass through, but I guess I missed the window to join that debate. |
Closing, I believe we should not call next as everything is handled internally. Happy to reconsider at a later date if enough arguments can be made ! |
So when I see poor performance from endpoints that Parse Server 'handles', I should dig in on those… how? |
we use connect-datadog for performance monitoring, I also recently used both NewRelic and AppDynamics for performance monitoring, I'm not sure what prevents you from doing the same. parse-server is not a middleware, it's a full blown express app. See: https://github.com/AppPress/node-connect-datadog/blob/master/lib/index.js#L11 Overriding |
Sorry to pick up a convo on a closed thread — when I've installed those tools (used NewRelic for a bit, using OpBeat now), the level of granularity I get is always no better than: i.e. things within the parse-server application are totally opaque, so I can't zero in on whether it's a slow mongo query, or slow assembly of mongo results, etc. Do you have a different experience with these tools and parse-server? If so, I guess I should figure out what's wrong with my configuration :-\ |
It’s usually because your injection of newrelic or other is not the 1st require. |
Definitely first thing.
bin/webstart:
index.js:
🤷♂️ |
I have no particular insight on opbeats, but we manage to successfully use either appDynamics, newRelic or even google cloud trace without any issue, as long as we loaded this module first. |
At the very beginning of its open source life, ParseServer was not calling
next()
to hand off execution to later middlewares — then (if my notes are correct), a change with version 2.2.16 ParseServer began callingnext()
after execution. We implemented a middleware directly after as a stopgap measure until we could properly deal with the fallthrough. But now it appears our middleware is not being called on requests that are Parse queries. Here's our setup:Currently using ParseServer 2.4.2. We're hoping to set up some server-wide instrumentation, which would require executing middlewares after parse-server even on routes it handled.
Thanks!
The text was updated successfully, but these errors were encountered: