/tonic-grpc-web-chat

Tonic(Rust) + grpc + grpc-web => chat

Primary LanguageJavaScript

GRPC chat system with Rust + Grpc-web

Using Tonic (Rust grpc framework) as backend system. Grpc-web as the frontend code.

screenshot.png

Folder struct

  • protos: define protobuf messages and services.
  • backend: use tonic as chat backend system.
  • frontend: grpc-web talk to backend. Insert js into index.html for demo.

Backend

I am using docker holding server with envoy.

  • Make sure the envoy.yaml is correct setting and running.
  • Do cargo run --bin server to launch server with developing mode. (Please feel free try release mode)

Frontend

  • Move into cd frontend folder.

  • Generate protobuf related js files (in codebase, both _pb.js already generated):

    protoc -I=../protos chat.proto

    --js_out=import_style=commonjs:./ --grpc-web_out=import_style=commonjs,mode=grpcwebtext:./

  • Compile JS library, please refer here

    • npm install
    • npx webpack client.js
  • Open index.html page in your browser.

    (You may got domain issue when visiting page, disable security to access chromium --disable-web-security --disable-gpu --user-data-dir=./chrometest).