I'm novice in gRPC. My program is written with nuxtjs and is a simple login page that receives the username and password and sends it to the server using gRPC.
Everything is fine when I submit a request with 
Do I have to do a specific configuration?
I just want a hint for configuring.
UPDATE:
CodePudding user response:
Where was the problem?
The problem is that requests do not reach the server. So it does not matter if the server is up or down.
> Short Answer:
I needed a proxy to receive requests from the server. So I used 
> Long Answer:
1. Generate html/css/js file with building nuxt project.
I put my website files in the root/site folder.
2. envoy config:
I config envoy.yaml file as follows according to what the documentions grpc-web said.
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 5000 }
filter_chains:
- filters:
- name: envoy.filters.network.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: sample_cluster
max_grpc_timeout: 0s
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: grpc-status,grpc-message
http_filters:
- name: envoy.filters.http.grpc_web
- name: envoy.filters.http.cors
- name: envoy.filters.http.router
clusters:
- name: sample_cluster
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
hosts: [{ socket_address: { address: 0.0.0.0, port_value: 50051 }}]
This yaml file has two parts listeners and clusters. In the first part(listeners), we specify which port and address for listening(For example, here is address 0.0.0.0 and port 5000), and in the second part(clusters), we tell it where to send the requests(here is address 0.0.0.0 and port 50051). To use this file, we give it to Docker. So I create a Dockerfile.
# Dockerfile
FROM envoyproxy/envoy:v1.14.3
COPY ./envoy.yaml /etc/envoy/envoy.yaml
EXPOSE 5000
CMD /usr/local/bin/envoy -c /etc/envoy/envoy.yaml
To build the container, I use the following commands inside Dockerfile folder and then run it.
docker build -t my-grpc-container:1.0.0 .
docker run -d my-grpc-container:1.0.0
By executing the above commands,
envoyis up and listens to port 5000 and sends requests to port 500051.
For more information about envoy read this nice blog:
The role of Envoy:
Envoy translates the HTTP/1.1 calls produced by the client into HTTP/2 calls that can be handled by those services (gRPC uses HTTP/2 for transport).
3. nginx config:
I went to the /etc/nginx/sites-enabled/ folder and open default file and set the path of my website files(see section 1) as follows:
# server block
root /root/site;
Then told nginx that if a request in the url started with /rpc/, send it to 5000 port(where envoy is listening):
# server block
location /rpc/ {
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:5000/;
}
Then I restart nginx:
sudo systemctl restart nginx
By doing this part,
nginxis up and send requests that start with/rpc/to port 5000, whereenvoyis ready to receive.
In summary:
- The server is running on port 50051.
-
nginxsends requests to port 5000. envoy, as an interface between theserverandnginx, receives requests from port 5000 and sends them to port 50051.
Done
CodePudding user response:
According to chrome screenshot you trying to access to 5005 port in JS, but according to BloomRPC, screenshot your service listening 50051.

