-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Feature Request: return result of calling handler #51
Comments
Wouldn't that conflict with us being able to add promise support to the router? How would a passthrough return work as soon as there is one async handler in the chain? Please provide a more detailed outline of what you're think of, how it would work with all the various use cases and the ecosystem at large, thanks! |
Right now the router calls this function: (this function does not return anything) What if layer.handle_request were to return the result of calling the handler and the router function would also return the value that is returned from layer.handle_request? Basically whatever the handler functions returns the router should just pass through the return I think the creator of original router library in express did not even think of a case that handler may actually return some value. What I have is controller that has same signature as all controllers have (req, res) but it actually returns Promise of response right away. I am just looking for a router for my project that would be able to handle this case. So far I was unable to find any. Only 2 small changes are required to your router library, just adding "return" word in 2 places. I will not break any existing functionality, right now it just returns undefined and it will be returning a value. If you plan to add promise support to router, it will not prevent you from doing so. You can just wrap returned value of Promise.resolve(result) and return that... It will work for me just as well. But I think you should just pass through return value from controller and let the user decide what they want to do with it. |
This is what I want to do: var Router = require('router') Instead of this: I want to do this: This is the type of framework I am creating, where controllers always return promise of response (custom object that has responseCode, headers and body) and never directly write to res object. |
PR #32 sounds like it implements what you're asking for, so I'm going to close this as a duplicate. Let me know if you believe you're asking for something different than that PR. |
@dougwilson Note that this request is effectively for "upstream" support, but proper upstream support is impossible in the current module. This is because every existing piece of middleware is not written to cater for function useLegacy (middleware) {
return function (req, res, next) {
return new Promise((resolve, reject) => {
middleware(req, res, (err) => err ? reject(err) : resolve(err))
}).then(() => next())
}
} |
@snytkine Also, you might be interested in |
The one shortcoming with express router is that it does not have a return statement for calling handler.
I wrote a custom request handler that returns a Promise instead of service response right away.
I really need a router that returns the result of call to handler.
I think it will not break anything if you just add return statement to Layer and to Router function.
That would be awesome.
The text was updated successfully, but these errors were encountered: