grpc-web client in reactjs
See original GitHub issueHi,
my grpc client is react js, server grpc in csharp
Docker on windows 10 with envoy proxy running.
I run this command and generated my js files (on linux ubuntu 16):
sudo protoc -I=. proto.proto --js_out=import_style=commonjs:generated --plugin=protoc-gen-grpc-web=/home/grpc-web-master/javascript/net/grpc/web/protoc-gen-grpc-web --grpc-web_out=import_style=commonjs,mode=grpcwebtext:generated
Now in the client side:
import { ProtocolServiceClient } from '../output/proto_grpc_web_pb'
import { UserInfo } from "../output/proto_pb";
const grpcHost = "http://127.0.0.1:8085";
const client = new ServiceClient(grpcHost, {}, {});
const request = new UserInfo();
request.setName('a');
const metadata = {};
client.connect(request, metadata ,function(err, response) {
if (err) {
console.log(err.code);
console.log(err.message);
} else {
console.log(response);
}
});
Tried to add metaadata to the request with so many types of metadata, nothing worked
metadata = {'content-type': 'application/grpc-web-text'};
metadata = {'content-type': 'application/grpc'};
metadata = {'content-type': 'application/grpc-web'};
metadata = {'content-type': 'application/grpc-web+proto'};
metadata = {'content-type': 'application/grpc-web+json'};
And the result is: POST http://127.0.0.1:8085/ProtocolProtos.ProtocolService/Connect 503 (Service Unavailable) And receive back a gRPC error code 14 => upstream connect error or disconnect/reset before headers
What am I missing? Please help me, I’m a struggling with this for a very long time.
Here is my envoy.yaml file:
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 9903
static_resources:
listeners:
- name: listener_0
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 8085
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: protocol_service
max_grpc_timeout: 10s
cors:
allow_origin:
- "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: custom-header-1,grpc-status,grpc-message
enabled: true
http_filters:
- name: envoy.grpc_web
- name: envoy.cors
- name: envoy.router
clusters:
- name: protocol_service
connect_timeout: 0.25s
type: LOGICAL_DNS
# Comment out the following line to test on v6 networks
# dns_lookup_family: V4_ONLY
lb_policy: ROUND_ROBIN
http2_protocol_options: {}
hosts:
- socket_address:
address: 0.0.0.0
port_value: 9090
And here is my Dockerfile:
FROM envoyproxy/envoy:latest
COPY envoy.yaml /etc/envoy/envoy.yaml
CMD /usr/local/bin/envoy -c /etc/envoy/envoy.yaml
To run the image I did:
docker build -f envoyDockerfile -t envoy:v14 . docker run -d --name envoyv148085 -p 9903:9903 -p 8085:8085 envoy:v14
Any help figuring out why it doesn’t work will be highly appreciated.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7
Thanks for your help everyone! Indeed it works with
host.docker.internal
. Now I understand my mistake. My code is hosted here.@alce All are on one windows machine the docker, the image and the gRPC. What address exactly should be changed to’ host.docker.internal’, what does it mean?