Title: Add runtime-agnostic WebSocket routing to `@bquery/bquery/server` by Copilot · Pull Request #88 · bQuery/bQuery · GitHub
Open Graph Title: Add runtime-agnostic WebSocket routing to `@bquery/bquery/server` by Copilot · Pull Request #88 · bQuery/bQuery
X Title: Add runtime-agnostic WebSocket routing to `@bquery/bquery/server` by Copilot · Pull Request #88 · bQuery/bQuery
Description: The server backend stopped at HTTP middleware/routing and did not provide a first-class path for WebSocket upgrades. This change extends @bquery/bquery/server with explicit WebSocket route registration and a runtime-agnostic session layer so upgrade handling can plug into Bun/Deno/Node-style hosts without changing the existing HTTP flow. Server API Added app.ws(path, handler, middlewares?) for WebSocket routes alongside existing HTTP method helpers Added app.handleWebSocket(request) to resolve upgrade requests into either: null when the request is not a WebSocket handshake or no route matches a Response when middleware/error handling short-circuits a ServerWebSocketSession when the upgrade should be accepted Added isWebSocketRequest() and isServerWebSocketSession() helpers for adapter/runtime integration Session model Introduced runtime-agnostic server WebSocket types: ServerWebSocketSession ServerWebSocketPeer ServerWebSocketConnection ServerWebSocketHandlerSet ServerWebSocketRouteHandler Session callbacks cover onOpen, onMessage, onClose, and onError Added socket.sendJson() for structured outbound messages Normalized requested subprotocols and preserved route params, query, and middleware-populated state inside the session context Behavior WebSocket routes reuse the existing middleware pipeline instead of introducing a parallel stack Middleware can short-circuit upgrades with a normal Response Incoming text frames default to JSON parsing with raw-string fallback for non-JSON payloads Existing HTTP handle() behavior remains unchanged Docs and public surface Updated server guide and top-level project summaries to document the new backend WebSocket flow Synced server exports and full-bundle metadata with the new public API import { createServer, isServerWebSocketSession, isWebSocketRequest, } from '@bquery/bquery/server'; const app = createServer(); app.ws('/chat/:room', (ctx) => ({ protocols: ['chat'], onOpen(socket) { socket.sendJson({ type: 'ready', room: ctx.params.room }); }, onMessage(message, socket) { socket.sendJson({ type: 'echo', message }); }, })); export async function handler(request: Request) { if (!isWebSocketRequest(request)) { return app.handle(request); } const result = await app.handleWebSocket(request); if (result instanceof Response || result === null) { return result ?? new Response('Not Found', { status: 404 }); } if (isServerWebSocketSession(result)) { const { socket, response } = Deno.upgradeWebSocket(request, { protocol: result.protocols[0], }); socket.onopen = () => void result.open(socket); socket.onmessage = (event) => void result.message(socket, event); socket.onclose = (event) => void result.close(socket, event); socket.onerror = (event) => void result.error(socket, event); return response; } return new Response('Upgrade failed', { status: 500 }); }
Open Graph Description: The server backend stopped at HTTP middleware/routing and did not provide a first-class path for WebSocket upgrades. This change extends @bquery/bquery/server with explicit WebSocket route registra...
X Description: The server backend stopped at HTTP middleware/routing and did not provide a first-class path for WebSocket upgrades. This change extends @bquery/bquery/server with explicit WebSocket route registra...
Opengraph URL: https://github.com/bQuery/bQuery/pull/88
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:58c6b530-571b-f5fb-7a3d-d402745c360d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B5A6:9C379:BAD523:BF1325:6A4DB944 |
| html-safe-nonce | df08380930ef96f4c8aef4be9f992eb5d4170a4750d1a3069fb1ea2e090b7c85 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUE2OjlDMzc5OkJBRDUyMzpCRjEzMjU6NkE0REI5NDQiLCJ2aXNpdG9yX2lkIjoiNDM0NDkyNjk2Mjk2MDkzOTMzMiIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 5d8cad2f3210d61d0645d7acd828ded9697c66f36f81a7248fe212b5b3d647d4 |
| hovercard-subject-tag | pull_request:3603065417 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/bQuery/bQuery/pull/88/files |
| twitter:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| og:image:alt | The server backend stopped at HTTP middleware/routing and did not provide a first-class path for WebSocket upgrades. This change extends @bquery/bquery/server with explicit WebSocket route registra... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/bQuery/bQuery git https://github.com/bQuery/bQuery.git |
| octolytics-dimension-user_id | 256381806 |
| octolytics-dimension-user_login | bQuery |
| octolytics-dimension-repository_id | 1139284244 |
| octolytics-dimension-repository_nwo | bQuery/bQuery |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1139284244 |
| octolytics-dimension-repository_network_root_nwo | bQuery/bQuery |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32f7b614aca06e6bbd89842b1370df1328264f68 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width