Skip to content

equivalent of express .res.locals #1011

Answered by yusukebe
ahmafi asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ahmafi

The answer is probably yes. Try this:

type Variables = {
  message: string
}

const app = new Hono<{ Variables: Variables }>()

app.use('*', async (c, next) => {
  c.set('message', 'This is a message')
  await next()
})

app.get('/', (c) => {
  const message = c.get('message')
  return c.text(message) // Hello!
})

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ahmafi
Comment options

@yusukebe
Comment options

Answer selected by ahmafi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants