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

passing data from middleware to controller #227

Closed
moncefplastin07 opened this issue Aug 6, 2020 · 2 comments
Closed

passing data from middleware to controller #227

moncefplastin07 opened this issue Aug 6, 2020 · 2 comments
Labels
question A general question versus an issue or defect

Comments

@moncefplastin07
Copy link

moncefplastin07 commented Aug 6, 2020

can i pass data from the middleware to controller ?!

like this node

function middleware(req, res, next){
     req.user = {user:"incoming data"}
    next()
}

function controller(req, res){
     console.log(req.user) // {user:"incoming data"}
}
@kitsonk kitsonk added the question A general question versus an issue or defect label Aug 7, 2020
@kitsonk
Copy link
Collaborator

kitsonk commented Aug 7, 2020

This is what ctx.state is for. Ref: https://github.com/oakserver/oak#context

@kitsonk kitsonk closed this as completed Aug 7, 2020
@kitsonk
Copy link
Collaborator

kitsonk commented Aug 7, 2020

Since this has come up a few times, adding an FAQ: https://oakserver.github.io/oak/FAQ#how-do-i-pass-custom-propertiesstate-around

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A general question versus an issue or defect
Projects
None yet
Development

No branches or pull requests

2 participants