Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

WebSocket does not work with wrangler dev #2079

Closed
mnixry opened this issue Sep 18, 2021 · 4 comments
Closed

WebSocket does not work with wrangler dev #2079

mnixry opened this issue Sep 18, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mnixry
Copy link

mnixry commented Sep 18, 2021

🐛 Bug report

Describe the bug

Cloudflare Worker supports establish experimental WebSocket connection with users, which could work with production environment perfectly. But development server started by wrangler dev does not work.

With default config, we cannot built any WebSocket connection because worker cannot receive Upgrade header

Once set up configs below, Worker can receive Upgrade header and could establish a WebSocket connection, but it disconnected immediately

local_protocol = "http"
upstream_protocol = "http"

Reproduce the bug

Create a worker provides WebSocket server with official demo

Environment and versions

Fill out the following information about your environment.

  • operating system: Manjaro 21.1.4
  • output of wrangler -V: wrangler 1.19.3-rc.1
  • output of node -v: v16.9.1
  • content of wrangler.toml:
name = "onebot-worker"
type = "javascript"
zone_id = ""
account_id = ""
route = ""
workers_dev = true

[dev]
local_protocol = "http"
upstream_protocol = "http"

[build]
command = "npm run build"

[build.upload]
format = "service-worker"
@mnixry mnixry added the bug Something isn't working label Sep 18, 2021
@threepointone
Copy link
Contributor

Good catch, we should definitely fix this.

@threepointone
Copy link
Contributor

  • As a workaround, please consider using https://miniflare.dev/ for local development involving WebSockets (This is a project blessed by cloudflare, and we'll be collaborating with the package and its author more deeply).
  • The proper fix involves updating our local proxy to upgrade the connection and proxying websocket messages correctly, which we'll do as soon.

I'm going to leave this issue open till we have a proper fix.

@jyn514
Copy link
Contributor

jyn514 commented Feb 15, 2022

Fixed in #2135 and #2153.

@jyn514 jyn514 closed this as completed Feb 15, 2022
@ben-xD
Copy link

ben-xD commented Mar 27, 2022

Unfortunately, I am not able to connect to my localhost worker - which I started with cloudflare dev.

I get 2 errors in Firecamp (websocket client):

  • error: connect ECONNREFUSED 127.0.0.1:8787
  • 1006: A connection was closed abnormally, when a status code is expected.

It works when connecting to a worker.dev worker.
firecamp@2x

my project is open source at https://github.com/ben-xD/listenos/blob/main/backend/src/realtime/websocket_session.ts

Do you know what's going wrong?

I am using the latest wrangler beta: "wrangler": "^0.0.23"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants