Skip to content
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

Cloudflare Workers support #1274

Closed
jakubno opened this issue Oct 11, 2024 · 1 comment
Closed

Cloudflare Workers support #1274

jakubno opened this issue Oct 11, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jakubno
Copy link

jakubno commented Oct 11, 2024

Description

I am currently unable to run our SDK on cloudflare workers. We are using connectRPC in our SDK and we would like to support cloudflare workers for our users.

I've found some information about support for CF workers in v2. Is there any estimate when you plan to release v2?

If you need any additional info, let me know

Minimal example to reproduce:

import { createConnectTransport } from '@connectrpc/connect-node' // I've tried browser as well
import { createClient } from '@connectrpc/connect'
import { Filesystem as FilesystemService } from './filesystem/filesystem_connect'

interface Env {}
export default {
  async fetch(): Promise<Response> {
    const transport = createConnectTransport({
      httpVersion: '2',
      baseUrl: 'https://example.com/my-api',
      useBinaryFormat: false,
    })

    const client = createClient(FilesystemService, transport)
    await client.listDir({ path: 'path/to/dir' })
    const options = { headers: { 'content-type': 'text/plain' } }
    return new Response('hello world!', options)
  },
} satisfies ExportedHandler<Env>

package.json

{
  "name": "divine-hat-13c9",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest",
    "cf-typegen": "wrangler types"
  },
  "dependencies": {
    "@cloudflare/vitest-pool-workers": "^0.5.2",
    "@cloudflare/workers-types": "^4.20241004.0",
    "typescript": "^5.5.2",
    "@connectrpc/connect": "^1.6.0",
    "@connectrpc/connect-node": "^1.6.0",
    "@connectrpc/connect-web": "^1.6.0",
    "wrangler": "^3.60.4"
  }
}

wrangler.toml

#:schema node_modules/wrangler/config-schema.json
name = "e2b-test"
main = "src/index.ts"
compatibility_date = "2024-10-04"
compatibility_flags = [ "nodejs_compat_v2"]

[observability]
enabled = false

I've tried both @connectrpc/connect-node and @connectrpc/connect-browser. None of them worked, I was getting following errors:

For node + httpVersion 2:

[unenv] http2.connect is not implemented yet!

For node + httpVersion 1.1:

https.request is not implemented yet!

For browser:

 Cause: Error: The 'mode' field on 'RequestInitializerDict' is not implemented.
@jakubno jakubno added the enhancement New feature or request label Oct 11, 2024
@jakubno jakubno changed the title Cloudflare Worker support Cloudflare Workers support Oct 11, 2024
@timostamm
Copy link
Member

Hey Jakub, you can work around this specific issue by using the transport from @connectrpc/connect-web, and providing a fetch option that drops the mode property when passing the request to fetch. You can find more details in #577.

Closing as a duplicate of #550 and #577.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants