Skip to content

Commit

Permalink
docs: add grpc web example
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Nov 17, 2024
1 parent e7fbacd commit 10001c3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ Upstream features:
```bash
cargo run -- -c=~/github/pingap/examples/proxy-upstream.toml --admin=127.0.0.1:3018
```

## Grpc-Web

- Insecure grpc-server
- Commonjs example static
- Locally trusted development certificates for 127.0.0.1

The key points of configuration are as follows:

- [upstreams.grpc-server] should choose h2 alpn
- [servers.grpc-web] should select grpc-web module
- [locations.grpc-server] should enable grpc_web

```bash
cargo run -- -c=~/github/pingap/examples/grpc-web.toml --admin=127.0.0.1:3018
```
87 changes: 87 additions & 0 deletions examples/grpc-web.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[certificates.medev]
is_default = true
tls_cert = """
-----BEGIN CERTIFICATE-----
MIIEljCCAv6gAwIBAgIQeYUdeFj3gpzhQes3aGaMZTANBgkqhkiG9w0BAQsFADCB
pTEeMBwGA1UEChMVbWtjZXJ0IGRldmVsb3BtZW50IENBMT0wOwYDVQQLDDR4aWVz
aHV6aG91QHhpZXNodXpob3VzLU1hY0Jvb2stQWlyLmxvY2FsICjosKLmoJHmtLIp
MUQwQgYDVQQDDDtta2NlcnQgeGllc2h1emhvdUB4aWVzaHV6aG91cy1NYWNCb29r
LUFpci5sb2NhbCAo6LCi5qCR5rSyKTAeFw0yMzA5MjQxMzA1MjdaFw0yNTEyMjQx
MzA1MjdaMGgxJzAlBgNVBAoTHm1rY2VydCBkZXZlbG9wbWVudCBjZXJ0aWZpY2F0
ZTE9MDsGA1UECww0eGllc2h1emhvdUB4aWVzaHV6aG91cy1NYWNCb29rLUFpci5s
b2NhbCAo6LCi5qCR5rSyKTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
ALuJ8lYEj9uf4iE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95g78UpZFCEVMnEmkBNb9pmrXRLDuWb0vLE6
B6YgiEP6xQKBgBOXuooVjg2co6RWWIQ7WZVV6f65J4KIVyNN62zPcRaUQZ/CB/U9
Xm1+xdsd1Mxa51HjPqdyYBpeB4y1iX+8bhlfz+zJkGeq0riuKk895aoJL5c6txAP
qCJ6EuReh9grNOFvQCaQVgNJsFVpKcgpsk48tNfuZcMz54Ii5qQlue29AoGAA2Sr
Nv2K8rqws1zxQCSoHAe1B5PK46wB7i6x7oWUZnAu4ZDSTfDHvv/GmYaN+yrTuunY
0aRhw3z/XPfpUiRIs0RnHWLV5MobiaDDYIoPpg7zW6cp7CqF+JxfjrFXtRC/C38q
MftawcbLm0Q6MwpallvjMrMXDwQrkrwDvtrnZ4kCgYEA0oSvmSK5ADD0nqYFdaro
K+hM90AVD1xmU7mxy3EDPwzjK1wZTj7u0fvcAtZJztIfL+lmVpkvK8KDLQ9wCWE7
SGToOzVHYX7VazxioA9nhNne9kaixvnIUg3iowAz07J7o6EU8tfYsnHxsvjlIkBU
ai02RHnemmqJaNepfmCdyec=
-----END PRIVATE KEY-----"""

[locations.grpc-server]
grpc_web = true
path = "/grpc.gateway.testing.EchoService"
upstream = "grpc-server"

[locations.grpc-web]
path = "/"
plugins = ["grpc-web-static"]

[plugins.grpc-web-static]
category = "directory"
path = "~/tmp/grpc/commonjs-example"
step = "request"

[servers.grpc-web]
addr = "127.0.0.1:3000"
enabled_h2 = true
global_certificates = true
locations = [
"grpc-web",
"grpc-server",
]
modules = ["grpc-web"]

[upstreams.grpc-server]
addrs = ["127.0.0.1:9090"]
alpn = "H2"

0 comments on commit 10001c3

Please sign in to comment.