-
Notifications
You must be signed in to change notification settings - Fork 297
feat: experimental defineWebSocketRoute #1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Deploying h3dev with
|
| Latest commit: |
fd6f13d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://71a3c637.h3dev.pages.dev |
| Branch Preview URL: | https://feat-definewebsocketroute.h3dev.pages.dev |
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
src/utils/route.ts
Outdated
| /** | ||
| * Additional route metadata | ||
| */ | ||
| meta?: Record<string, unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Middleware and meta are not supported. Types should be removed (at least untill they are supported by defineWebSocket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should take the comment line and leave a TODO ?
src/utils/route.ts
Outdated
| /** | ||
| * HTTP method for the route (typically 'GET' for WebSocket upgrades) | ||
| */ | ||
| method?: HTTPMethod; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebSocket handlers should not accept a method.
- Remove `method` parameter from WebSocketRouteDefinition (WebSocket routes always use GET) - Remove `middleware` and `meta` properties (not yet supported by defineWebSocketHandler) - Add TODO comments for future middleware and metadata support - Update tests to reflect changes - Remove custom method test case Addresses review comments from @pi0 and @productdevbook in PR #1149 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Merged latest changes from main branch to sync with upstream. Resolved conflicts: - src/index.ts: Added WebSocketRouteDefinition export alongside RouteDefinition - test/unit/package.test.ts: Added defineWebSocketRoute to exports list
- Replace deprecated _routes with ~routes notation - Replace app.fetch() with app.request() for consistency with main branch - All route tests now passing after merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Hi team! I've addressed all the review feedback: Changes made:
Commits:
The branch is ready for re-review! 🚀 |
Summary
cc: #1088
cc: #1138
defineWebSocketRouteutility function to simplify WebSocket route definitionsWebSocketRouteDefinitioninterface for type-safe WebSocket route configurationDescription
This PR introduces a new
defineWebSocketRoutefunction that provides a consistent API pattern withdefineRoutefor defining WebSocket endpoints. This makes it easier to create WebSocket routes as plugins that can be registered withapp.register().Interface Definition
Key design decisions:
GETmethod (standard for WebSocket upgrades)methodparameter - WebSocket protocol requires GETmiddlewareandmetasupport deferred until implemented in underlyingdefineWebSocketHandlerExample usage:
Compatibility with existing APIs
This is fully compatible with the existing
defineWebSocketHandler:Test plan
app.register()/ws/:id)Review feedback addressed
methodparameter - WebSocket routes always use GET (@pi0)middlewareandmetaproperties - not yet supported (@pi0)websocketnothandler(@pi0)