Skip to content

Comments

Expose Hono context in partyserverMiddleware callbacks#339

Merged
threepointone merged 1 commit intomainfrom
fix-310
Feb 22, 2026
Merged

Expose Hono context in partyserverMiddleware callbacks#339
threepointone merged 1 commit intomainfrom
fix-310

Conversation

@threepointone
Copy link
Collaborator

Summary

  • Passes the Hono Context as a third argument to onBeforeConnect and onBeforeRequest callbacks in partyserverMiddleware, giving access to c.env, c.var, c.get(), etc.
  • No changes to the core partyserver package — the middleware wraps user callbacks before forwarding to routePartykitRequest.

Fixes #310

Usage

type Env = { Bindings: { JWT_SECRET: string } };

app.use(
  '*',
  partyserverMiddleware<Env>({
    options: {
      onBeforeConnect(req, lobby, c) {
        const secret = c.env.JWT_SECRET;
        // validate token, set headers, etc.
      },
    },
  })
);

Test plan

  • tsc --noEmit passes for hono-party package
  • tsc --noEmit passes for fixtures/hono
  • hono-party builds successfully

Made with Cursor

Pass the Hono Context (c) as a third argument to onBeforeConnect/onBeforeRequest callbacks so handlers can access c.env, c.var, c.get(), etc. Adds a .changeset for a patch release, updates the Hono fixture and README to demonstrate using env bindings, and implements HonoPartyServerOptions plus wrapOptionsWithContext to close over the Hono context. Also adjusts middleware and handler wiring (createMiddleware generic, options wrapping, and handler signatures) to forward the context to partyserver callbacks.
@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2026

🦋 Changeset detected

Latest commit: 471ae43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hono-party Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2026

Open in StackBlitz

hono-party

npm i https://pkg.pr.new/cloudflare/partykit/hono-party@339

partyfn

npm i https://pkg.pr.new/cloudflare/partykit/partyfn@339

partyserver

npm i https://pkg.pr.new/cloudflare/partykit/partyserver@339

partysocket

npm i https://pkg.pr.new/cloudflare/partykit/partysocket@339

partysub

npm i https://pkg.pr.new/cloudflare/partykit/partysub@339

partysync

npm i https://pkg.pr.new/cloudflare/partykit/partysync@339

partytracks

npm i https://pkg.pr.new/cloudflare/partykit/partytracks@339

partywhen

npm i https://pkg.pr.new/cloudflare/partykit/partywhen@339

y-partyserver

npm i https://pkg.pr.new/cloudflare/partykit/y-partyserver@339

commit: 471ae43

@threepointone threepointone merged commit d1906a9 into main Feb 22, 2026
6 checks passed
@threepointone threepointone deleted the fix-310 branch February 22, 2026 18:44
@github-actions github-actions bot mentioned this pull request Feb 22, 2026
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

Successfully merging this pull request may close these issues.

Expose context on hono-party middleware

1 participant