Skip to content

Commit 53704f8

Browse files
committed
Initial commit
0 parents  commit 53704f8

18 files changed

+1120
-0
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203
4+
exclude = dist,.venv,.env,env,venv,.cache

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist/
2+
*_pb.js
3+
node_modules/
4+
package-lock.json
5+
.venv
6+
__pycache__
7+
*.pyc

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.venv:
2+
python3 -m venv .venv
3+
4+
python-lint:
5+
black --check server.py
6+
flake8 server.py
7+
8+
python-install: .venv
9+
.venv/bin/python3 -m pip install -r requirements.txt
10+
11+
protostubs:
12+
protoc -I=. helloworld.proto --js_out=import_style=commonjs:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
13+
PATH=.venv/bin .venv/bin/python3 -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. --mypy_out=. --mypy_grpc_out=. helloworld.proto
14+
15+
webpack:
16+
npx webpack client.js
17+
18+
all: protostubs webpack
19+
20+
install: python-install

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Note
2+
3+
This came from: https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld
4+
5+
# Install
6+
7+
* `brew install protoc-gen-grpc-web`
8+
* `npm install`
9+
* `make all`
10+
11+
# Also see: [original-README.md](original-README.md)

client.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
*
3+
* Copyright 2018 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
console.log("We're logging in the console.");
20+
21+
const {HelloRequest, RepeatHelloRequest,
22+
HelloReply} = require('./helloworld_pb.js');
23+
const {GreeterClient} = require('./helloworld_grpc_web_pb.js');
24+
25+
var client = new GreeterClient('http://127.0.0.1:5000', null, null);
26+
27+
// simple unary call
28+
var request = new HelloRequest();
29+
request.setName('A very big world');
30+
31+
client.sayHello(request, {}, (err, response) => {
32+
if (err) {
33+
console.log(`Unexpected error for sayHello: code = ${err.code}` +
34+
`, message = "${err.message}"`);
35+
} else {
36+
console.log(response.getMessage());
37+
}
38+
});
39+
40+
41+
// server streaming call
42+
/*
43+
var streamRequest = new RepeatHelloRequest();
44+
streamRequest.setName('World');
45+
streamRequest.setCount(5);
46+
47+
var stream = client.sayRepeatHello(streamRequest, {});
48+
stream.on('data', (response) => {
49+
console.log(response.getMessage());
50+
});
51+
stream.on('error', (err) => {
52+
console.log(`Unexpected stream error: code = ${err.code}` +
53+
`, message = "${err.message}"`);
54+
});
55+
*/

envoy.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
admin:
2+
access_log_path: /tmp/admin_access.log
3+
address:
4+
socket_address: { address: 0.0.0.0, port_value: 9901 }
5+
6+
static_resources:
7+
listeners:
8+
- name: listener_0
9+
address:
10+
socket_address: { address: 0.0.0.0, port_value: 8080 }
11+
filter_chains:
12+
- filters:
13+
- name: envoy.filters.network.http_connection_manager
14+
typed_config:
15+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
16+
codec_type: auto
17+
stat_prefix: ingress_http
18+
route_config:
19+
name: local_route
20+
virtual_hosts:
21+
- name: local_service
22+
domains: ["*"]
23+
routes:
24+
- match: { prefix: "/" }
25+
route:
26+
cluster: greeter_service
27+
max_stream_duration:
28+
grpc_timeout_header_max: 0s
29+
cors:
30+
allow_origin_string_match:
31+
- prefix: "*"
32+
allow_methods: GET, PUT, DELETE, POST, OPTIONS
33+
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
34+
max_age: "1728000"
35+
expose_headers: custom-header-1,grpc-status,grpc-message
36+
http_filters:
37+
- name: envoy.filters.http.grpc_web
38+
- name: envoy.filters.http.cors
39+
- name: envoy.filters.http.router
40+
clusters:
41+
- name: greeter_service
42+
connect_timeout: 0.25s
43+
type: logical_dns
44+
http2_protocol_options: {}
45+
lb_policy: round_robin
46+
# win/mac hosts: Use address: host.docker.internal instead of address: localhost in the line below
47+
load_assignment:
48+
cluster_name: cluster_0
49+
endpoints:
50+
- lb_endpoints:
51+
- endpoint:
52+
address:
53+
socket_address:
54+
address: 0.0.0.0
55+
port_value: 9090

helloworld.proto

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
package helloworld;
18+
19+
service Greeter {
20+
// unary call
21+
rpc SayHello(HelloRequest) returns (HelloReply);
22+
// server streaming call
23+
rpc SayRepeatHello(RepeatHelloRequest) returns (stream HelloReply);
24+
}
25+
26+
message HelloRequest {
27+
string name = 1;
28+
}
29+
30+
message RepeatHelloRequest {
31+
string name = 1;
32+
int32 count = 2;
33+
}
34+
35+
message HelloReply {
36+
string message = 1;
37+
}

helloworld_pb2.py

Lines changed: 193 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)