Comments (9)
I think I'm having the same issue. When I register a websocket handler in a group, like this:
import Elysia from "elysia";
new Elysia()
.group("/ws", (a) =>
a.ws("/", {
open() {
console.log("Hello");
},
}),
)
.listen(3000);
When trying to connect to it, i always get an error code 400 with this message:
Expected a websocket connection
I think it might have something to do with server
when upgrading the request. Maybe server
ist undefined | null, or another falsy value, thus the if upgrade fails, and this error is returned? (relevant code: https://github.com/elysiajs/elysia/blob/4a1134b082b726eb67b0581565628a1d697a0c18/src/index.ts#L2401C5-L2402C45)
I`m on elysia version 0.7.15
from elysia.
Thanks for the report, from a technical perspective, it's expected.
However, I think your approach should work by default too, and I update Elysia 0.3.2 to work with the first snippet.
Should be fixed with #f313078, please update to 0.3.2 to verify if your first snippet work.
from elysia.
I worked on my project further last night and somehow the websocket connection could not be established when it was defined inside the group. So now I moved it outside and it is working.
So from
import { Elysia, ws } from "elysia";
const app = new Elysia()
.use(ws())
.get("/", () => "Welcome to Elysia!")
.group("/group", (app) => app.get("/", myHandler).ws("/websocket", {}))
.listen(3000);
I moved to
import { Elysia, ws } from "elysia";
const app = new Elysia()
.use(ws())
.get("/", () => "Welcome to Elysia!")
.group("/group", (app) => app.get("/", myHandler))
.ws("/group/websocket", {})
.listen(3000);
from elysia.
Yes, that's expected. And I'm trying to make ws
inside group
work too.
With the patch of Elysia 0.3.2, this code should also work:
import { Elysia, ws } from "elysia";
const app = new Elysia()
.use(ws())
.get("/", () => "Welcome to Elysia!")
.group("/group", (app) => app.get("/", myHandler).ws("/websocket", {}))
.listen(3000);
Can you verify that the code above works on your end too?
from elysia.
Sorry, I wasn't working on my project for some days.
Should I test this again with v0.3.2 or directly with the latest v0.4.5?
from elysia.
0.4.5 should work
from elysia.
OK, I tested this extensively and when defining the websocket route inside a group, the connection can't be upgraded. I tried to debug this, but I can't see a reason for the upgrade failure, as Bun just returns a boolean when calling server.upgrade().
from elysia.
+1 same issue here with version 0.7.15
Unable to connect to ws after using it under group.
from elysia.
Fix with eabe264, available on 0.7.27.
Feel free to reopen if the issue still persists.
from elysia.
Related Issues (20)
- no catch case in case DELETE request has no body HOT 2
- `ws` type is not exported making it harder to store ws (WebSocket) objects in a TypeScript compliant way
- Add ability to use Connect middleware HOT 6
- Subscriptions work but the type annotations are wrong
- Endpoints with the same path but different method get mixed up types (using eden fetch)
- Beta: undefined class when using decorate and derive HOT 2
- Empty ObjectString missing validation inside query schema HOT 1
- Ability to rewrite an incoming request's url or have a prefix that's not actually added to the path?
- swagger breaks when used after logger
- Properly respect enums in OpenAPI/Swagger documentation HOT 2
- Elysia 1.0 Breaking Changes / Migration HOT 1
- t.String: String types with patterns must specify a default value
- 1.0.0-rc.0 server timing breaks beforeHandle guards HOT 2
- @elysiajs/[email protected] error typed as Unknown HOT 1
- Cookie settings not used
- Context not contains cookie element on 1.0.0-rc.6
- Swagger Adaptation Issue: Incorrect Response Examples Display HOT 3
- Using both Static and HTML plugins segfaults on Bun >=1.0.27 HOT 1
- Feature Request: Support Camel Case Access for Snake Case API Endpoints in Eden
- Minor DX request: Allow passing an `edenTreaty` value without a trailing slash HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elysia.