-
Notifications
You must be signed in to change notification settings - Fork 209
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
WebSocket usage with worktop #100
Comments
This is the core of worktop's request handler: let res;
try {
res = await handler(request, context);
} catch (err) {
// ...
} finally {
res = new Response(res ? res.body : 'OK', res);
return finalize(res, req.method === 'HEAD');
} In the My guess (without having looked at source) is that miniflare's |
Yeah, miniflare's And here's the part where our |
Hey! 👋 |
Hi. Thanks for the update. Now I'm getting this error instead.
|
Hmmm ok 😕, your very first code snippet doesn't throw for me now. That const [webSocket1, webSocket2] = Object.values(new WebSocketPair());
const res1 = new Response(null, {
status: 101,
webSocket: webSocket1,
});
const res2 = new Response(null, res1); // ✅
const res3 = new Response(null, {
status: 101,
webSocket: webSocket2,
});
const res4 = res3.clone(); // ❌ TypeError: Cannot clone a response to a WebSocket handshake. Are you able to share your worker script or a minimal reproduction? |
Can confirm the original script is working. What I changed was importing import { Router } from 'worktop'
import { reply } from 'worktop/cache'
import { listen } from 'worktop/ws'
const API = new Router()
API.add(
`GET`,
`/ws`,
listen((req, ctx, socket) => {
console.log(`connected`)
})
)
export default reply(API.run) Looks like the response is cloned here https://github.com/lukeed/worktop/blob/next/packages/worktop/src/cache.ts#L24. Thanks for taking a look. I will file an issue there. |
I'm using
worktop@0.8.0-next.8
withminiflare@2.0.0-rc.
. I got this error when trying to connect to ws route. Could you take a look? I understand that I'm using unstable releases.This is
index.js
.Same error when not using
worktop/ws
.The minimal ws example works fine.
I'm also using esbuild with below config, if that is useful.
The text was updated successfully, but these errors were encountered: