Rust gRPC server with built‑in gRPC‑Web support and a TypeScript (Vite) browser client. This repo shows an end‑to‑end setup where the browser talks to a Rust backend over gRPC‑Web without needing Envoy, thanks to tonic-web.
protos/grpc-web.proto– shared Protocol Buffers definitionsrust/grpc-web-server/– gRPC server implemented in Rust using tonic + tonic‑webweb/grpc-web-client/– Vite + TypeScript client that calls the server via gRPC‑Web
Services provided (from the proto and server):
- Echo: send a message and receive it back
- Math: perform add/subtract/multiply/divide via a
do_mathRPC
- Rust 1.70+
- Node.js 18+ and npm
- Protocol Buffer compiler (
protoc) - gRPC‑Web protoc plugin (
protoc-gen-grpc-web)- macOS (Homebrew):
brew install protobuf protoc-gen-grpc-web
- macOS (Homebrew):
- Start the Rust gRPC‑Web server (default listens on http://0.0.0.0:10000)
cd rust/grpc-web-server
cargo run- Install client deps and generate stubs (only needed if proto changed) and run the client (Vite on http://localhost:8080)
cd web/grpc-web-client
npm install
npm run proto-regen # or npm run proto-gen if you don’t need a clean
npm run devOpen http://localhost:8080 and try Echo and Calculator. The client calls the server at http://localhost:10000 using gRPC‑Web. CORS is enabled on the server for local development.
- Update shared messages/services in
protos/grpc-web.proto. - Rebuild the Rust server (build.rs will re‑generate Rust types via prost/tonic‑build).
- Re‑generate client code in
web/grpc-web-clientwithnpm run proto-regen.
- Server: build a release binary
cd rust/grpc-web-server
cargo build --release- Client: build static assets to
dist/
cd web/grpc-web-client
npm run buildServe the client’s dist/ behind your preferred static file server or CDN. Point it at the deployed server URL with gRPC‑Web enabled (and appropriate CORS/TLS in front if needed).
- Rust server: see
rust/grpc-web-server/README.md - Web client: see
web/grpc-web-client/README.md
- protoc or plugin not found: ensure
protocandprotoc-gen-grpc-webare installed and on PATH. - CORS errors in the browser: verify the server is running on
:10000and CORS is permissive for the dev originhttp://localhost:8080. - Proto not found: confirm
protos/grpc-web.protoexists and paths in scripts match.
This project is licensed under the terms of the LICENSE file in the repository root.