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

"RpcError: Failed to fetch" with Typescript, Vite and Vue #572

Open
zpervan opened this issue Jul 23, 2023 · 3 comments
Open

"RpcError: Failed to fetch" with Typescript, Vite and Vue #572

zpervan opened this issue Jul 23, 2023 · 3 comments

Comments

@zpervan
Copy link

zpervan commented Jul 23, 2023

Hey everyone and sorry if I am asking noobish questions as I am quite new to all of this.

Anyways, I try to create a gRPC client with Vite, TS and Vue, by using the protobuf-ts/grpcweb-transport, but I get the following error constatly:
image

The client code is currently also very simple, and goes something like this:

import {GrpcWebFetchTransport} from "@protobuf-ts/grpcweb-transport";
import {BackendServiceClient} from "./main.client.ts";

const transport= new GrpcWebFetchTransport({baseUrl: "http://localhost:3500", format:"binary"});
const client = new BackendServiceClient(transport);

export async function ping() {
    const call = await client.testConnection({dummyData: "Vue!!"}, {});
    return call;
}

I was researching about other approaches but I started to somehow run in circles... I also used the examples provided within these packages so my code looks similar and still has the same error. By this point, I assume the generated gRPC proto files are correct (also the command for generating files is taken from the examples).

The gRPC server is working as I verified it with BloomRPC and a simple Rust client - both can easily send the testConnection command and get a response.

Hope you can help me out here.

Package versions:

    "@grpc/grpc-js": "^1.2.2",
    "@protobuf-ts/plugin": "^2.9.0",
    "@protobuf-ts/protoc": "^2.9.0",
    "@protobuf-ts/runtime": "^2.9.0",
    "@protobuf-ts/runtime-rpc": "^2.9.0",
    "@protobuf-ts/grpcweb-transport": "^2.9.0",
    "vue": "^3.3.4"
    "typescript": "^5.1.6",
    "vite": "^4.4.5",
@jcready
Copy link
Contributor

jcready commented Jul 26, 2023

You need to use a grpc-web proxy in front of your grpc service to translate between the two different protocols.

@bahag-ongwl
Copy link

You need to use a grpc-web proxy in front of your grpc service to translate between the two different protocols.

hi, do you have an example of how to implement this proxy?

@jcready
Copy link
Contributor

jcready commented Mar 12, 2024

Envoy is one such proxy which supports grpc to grpc-web translation. The grpc-web protocol is described in more detail here.

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

No branches or pull requests

3 participants