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

Provide express' req/res.locals inside HandlerContext #586

Closed
kruegernet opened this issue Apr 17, 2023 · 3 comments
Closed

Provide express' req/res.locals inside HandlerContext #586

kruegernet opened this issue Apr 17, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@kruegernet
Copy link

Is your feature request related to a problem? Please describe.
When migrating an existing express/REST service to use connect/gRPC, it will be a typical scenario that an RPC handler must work with the existing express middleware. If we cannot access req.locals or res.locals, for some users adopting connect-es will be impossible.

Describe the solution you'd like
Please provide access to req/res.locals via the HandlerContext.

This request is for Connect for Node.js.

Describe alternatives you've considered
I would personally prefer, at least during beta, that the entire raw express req and res are exposed to us via HandlerContext. It's not clear to me how you all plan to address authentication/authorization or middleware generally, or how you intend to relate http middleware to gRPC interceptors. Until these are resolved it remains unclear how folks can migrate existing services or do serious work with connect-es.

@mfecteau42
Copy link

mfecteau42 commented Jun 12, 2023

We nearly got our API migrated from grpc-js to connect-es. Everything went smoothly, but unfortunately we hit a wall with this (lack of access to res.locals). We hope this will be fixed, or that an alternative could be found. Server interceptors is not available in plain grpc-js, but at least a nice workaround is possible that gives access to a variable similar to res.locals (ctx). It doesn't seem possible to do the same with connect-es.

@mfecteau42
Copy link

A workaround was found by modifying this file : @bufbuild/connect/dist/esm/protocol-connect/handler-factory.js

By adding this code at the right place, in both functions createUnaryHandler and createStreamHandler, the res.locals variable becomes available :

if (req.locals) {
    context.locals = req.locals
}

@srikrsna-buf
Copy link
Member

#835

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

No branches or pull requests

3 participants