Skip to content

[Discussion] universal-middleware/hono #26

Closed
@fortezhuo

Description

I still don't get about universal middleware.

I have code like this using hono

export const preference = (): MiddlewareHandler => {
  return async function preference(c, next) {
    const cookiePreference = getCookie(c, "preference")
    const preference = cookiePreference
      ? JSON.parse(cookiePreference)
      : PREFERENCE
    c.set("preference", preference)
    await next()
  }
}

export const ssr = () =>
  vikeNode({
    pageContext: (c: Context) => {
      return {
        preference: c.var.preference,
        user: c.var.user,
        vendor: c.var.vendor,
      }
    },
    static: {
      root: distClient,
    },
  })

instance.use(preference())
instance.use(ssr())

And with universal-middleware, can I still use hono context using native behavior like c.var and c.set ?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions