workers-sdk: ๐Ÿ› BUG: Using both `--route` and `--remote` causes WebSocket error

Which Cloudflare product(s) does this pertain to?

Wrangler core

What version(s) of the tool(s) are you using?

3.5.0

What version of Node are you using?

20.5.1

What operating system are you using?

macOS Ventura 13.5

Describe the Bug

  1. Create index.js file:
export default {
	fetch(req) {
		const url = new URL(req.url);
		return new Response(`Your hostname is: ${url.hostname}`);
	}
}
  1. Run Wrangler Dev with both --remote and --route flags(with a zone you have access to):
$ wrangler dev index.js --route "goalastair.com/*" --remote
 โ›…๏ธ wrangler 3.5.0
------------------
โฌฃ Listening at http://0.0.0.0:8787
- http://127.0.0.1:8787
- http://192.168.32.2:8787
Total Upload: 5.96 KiB / gzip: 1.84 KiB
โ–ฒ [WARNING] worker failed to prewarm:  Bad Gateway


Waiting for connection...
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [l] turn on local mode, [c] clear console, [x] to exit                                                                                                                  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:30632
            throw a;
            ^

Error: WebSocket was closed before the connection was established
    at WebSocket2.close (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:108521:11)
    at close (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:127122:14)
    at /Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:127230:7
    at jh (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:29688:15)
    at exports2.unstable_runWithPriority (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:25660:16)
    at Pc (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:26308:16)
    at Qg (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:29651:18)
    at /Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:29640:13
    at V (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:25585:22)
    at Timeout.w [as _onTimeout] (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:25420:13)
Emitted 'error' event on WebSocket instance at:
    at emitErrorAndClose (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:108968:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.5.1

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Thanks @helloimalastair โ€”in that case Iโ€™ll close this issue. The hotkey bug is captured in https://github.com/cloudflare/workers-sdk/issues/3907, I think

Been waiting on this issue for some months now as well. My workaround was to comment out [route] definition from wrangler.toml each time I was running my projects locally, but also needed to remember to un-comment before any commits/deploysโ€ฆ

Just discovered today that you can pass --routes=[] on your command via package.json scripts and it will overwrite the definition from wrangler.toml.

So, the config may look like this:

wrangler.toml:

name = "my-worker"
main = "src/worker.ts"
compatibility_date = "2023-10-23"

workers_dev = false

[route]
  pattern = "worker.example.com"
  custom_domain = true

package.json:

{
  "scripts": {
    "dev": "wrangler dev --remote --routes=[]"
  }
}

Hopefully we can get come kind fix, or at least, a flag to bypass routes when using --remote.