Skip to content

feat(adapter): add Bun WebSocket integration hooks - #7

Merged
abejarano merged 1 commit into
mainfrom
feat/bun-websocket-hooks
Sep 10, 2026
Merged

abejarano merged 1 commit into
mainfrom
feat/bun-websocket-hooks

Conversation

@abejarano

Copy link
Copy Markdown
Owner

Summary

  • adds BunWebSocketAdapter for libraries that need direct access to Bun's native fetch and websocket handlers
  • runs beforeFetch before the normal Bun Platform Kit router and exposes next() as the HTTP fallback
  • keeps the existing BunAdapter and BunKitServer behavior unchanged
  • adds runtime coverage proving intercepted requests are handled first and normal routes still work
  • documents the integration pattern for engines such as @socket.io/bun-engine

Why

Socket.IO's Bun engine must participate directly in Bun.serve({ fetch, websocket }). The current service lifecycle only receives the framework ServerInstance, which is not a Node http.Server, so Node-style new SocketIOServer(httpServer) cannot handle WebSocket upgrades.

Validation

  • build
  • typecheck
  • tests

@abejarano
abejarano force-pushed the feat/bun-websocket-hooks branch from 2b9fde4 to 67838d5 Compare September 10, 2026 13:01
@abejarano
abejarano merged commit 87fe99a into main Sep 10, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b9fde4b4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/BunWebSocketAdapter.test.ts Outdated
const app = adapter.createApp();
app.set?.("hostname", "127.0.0.1");
adapter.configure(app, port);
app.get("/health", (_req, res) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Register the fallback endpoint through a router

When this test runs, adapter.createApp() returns BunApp, whose get(key) method reads application settings and overrides the inherited BunRouter.get(path, ...handlers) route-registration method. Consequently this call does not register /health, and bun test tests/BunWebSocketAdapter.test.ts deterministically receives 404 at the fallback assertion. Create a router with adapter.createRouter(), register the route there, and mount it with app.use(...) as the production modules do.

Useful? React with 👍 / 👎.

@abejarano

Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant