PART 1 - How To Compile Protobuf in Windows Environment - REACT
This article discusses how to compile gRPC-Web's Protobuf file for React (or other JavaScript-based web app) in Windows environment. Thi is only front-end side. The backend must be setup as gRPC-Web server using .NET gRPC service with gRPC-Web or Envoy proxy.
In order for gRPC-Web clients to communicate with the backend gRPC-Web servers, the fontend apps must have Protobuf compilation files.
There are many articles out on the internet, but they are very scattered so I tried to compile all in to one.
You can use either PowerShell or Command Prompt.
!!! WARNING - Make sure you add the tools' install folder locations to Windows System Environment Variables !!!
choco install bazelisk
git clone https://github.com/protocolbuffers/protobuf-javascript
cd protobuf-javascript/
bazel build //generator:protoc-gen-js
Install the following libraries on your React project (e.g. use npm install command).
a. Using either Command Prompt or Powershell, go to the root folder of the React project
b. Enter the following command and then press enter (there are areas where you must change the command as per your project settings - locations of proto-gen-js.exe file and .proto file)
protoc --plugin=\protoc-gen-js.exe [folder where proto-gen-js.exe is located]\protoc-gen-js.exe --proto_path=. src/protos/greet.proto --js_out=import_style=commonjs:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
If you get an error after entering this command, mostly it is due to the incorrect or missing Windows System Environment Variable. You must double check the settings and then you MUST close exit the current PowerShell or Command Prompt window to start from the Step 1 again
c. If you did not get any error messages, you will see two .js files in src/protos folder as below:
You are all set. Review those .js files to find out how to set or call gRPC-Web service parameters and so on, as the syntax is "case-sensitive".
Part 2:
https://ranku.tistory.com/162
Table-Valued Function (TVF) Explained (with Examples) - T-SQL (0) | 2023.02.19 |
---|---|
Create A Versatile and Stable Popup Window For All OS's and Browsers - JavaScript (0) | 2023.02.18 |
PART 2 - How To Get Data from gRPC-Web Server using the Prot - REACT (0) | 2023.01.29 |
Add CORS To gRPC-Web Server - C# & .NET (0) | 2023.01.29 |
How To Create gRPC Server in .NET and Add gRPC-Web - C# & .NET (0) | 2023.01.29 |