I'm trying to implement gRPC gateway in a Node.JS server following the installation guide.
The steps are writen for golang
but I tried to do in Node.JS.
I found this response, and also some packages like this one so is possible implement in node.
After read "insatallation guide", the main problem seems to be get the binary files:
- protoc-gen-grpc-gateway
- protoc-gen-openapiv2
- protoc-gen-go
- protoc-gen-go-grpc
I have downloaded first two binaries from here so the problem maybe are last two.
I assume go
is from golang
so I have to search something like protoc-gen-node-grpc
. And I've seen this npm package, but, I want to implement by myself as much as is possible. I don't want to depends from third-party people.
At this point I have first to binaries into my path but no the last two.
Once defined gRPC service, next step is generate gRPC stubs. I have this line:
RUN protoc -I=. mygrpc.proto --js_out=import_style=commonjs,binary:./my/folder/ --grpc-web_out=import_style=commonjs,mode=grpcwebtext:./my/folder/
And this generate the files ok. I don't know if I have to use --js_out
and --grpc-web_out
to create client and service files.
Then, next step is to generate reverse-proxy using protoc-gen-grpc-gateway
.
I do (as guide says):
protoc -I=./my/path/ myproto.proto
--grpc-gateway_out ./my/path/
--grpc-gateway_opt logtostderr=true
--grpc-gateway_opt paths=source_relative
--grpc-gateway_opt generate_unbound_methods=true
And this generate a .go
file: myproto.pb.gw.go
.
Into the file says:
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: myproto.proto
/*
Package myproto is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
So I assume steps are correctly done but: How can I execute this into my Node.JS server?
I have a node project using a Express API, I want to use grpc-gateway instead of express API endpoint... but I only have a .go
file.
My proto version is:
libprotoc 3.14.0
Thanks in advance.
question from:
https://stackoverflow.com/questions/65617258/how-to-implement-grpc-gateway-in-a-node-backend 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…