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

req.context not available for app.use() #149

Closed
renhiyama opened this issue Jul 21, 2022 · 1 comment
Closed

req.context not available for app.use() #149

renhiyama opened this issue Jul 21, 2022 · 1 comment

Comments

@renhiyama
Copy link

This code works:

const router = createRouter()
 .get('/', () => 'Hello World!')
 .get('/hello/:name', req => `Hello ${req.context.params.name}!`)

app.use(router)

But this wont:

app.use("/",(req,res)=>  `Hello ${req.context.params.name}!`)

And app.get doesnt even exist like expressjs has...
I dont want to create a new router, but straight away use app.use if possible. Thanks.

@pi0
Copy link
Member

pi0 commented Aug 3, 2022

Hi dear @renhiyama. You should use eventHandler wrapper to create new handlers. Legacy (req, res) is going to be unsupported soon.

import { eventHandler } from 'h3'
app.use("/", eventHandler((event)=>  `Hello ${event.context.params.name}!`))

Also @NozomuIkuta made a some new utils to access params. Check #158.

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

No branches or pull requests

2 participants