How to implement gRPC Gateway in a node backend - grpc

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.

As the issue comment, grpc-gateway only generate Go code. Feel free to use Go, there only need generate code from proto and add service. You can reference my sample code in Java helloworlde/grpc-gateway; And buf is better than protoc to generate code. If you want write all by yourself, you can reference ReflectionCall.java wirte in Java, it can call server without generate code.

Related

Grab files changed by commit from GitLab API

I am trying to use the GitLab API to grab all files changed by a particular commit, but I don't see a good way of doing it.
In other words, whats the equivalent of git show --name-only sha1 in the GitLab API?
The only way I know of is using the following API Call.
GET /projects/:id/repository/commits/:sha/diff
(See: https://docs.gitlab.com/ee/api/commits.html#get-the-diff-of-a-commit)
If you only need the changed files, you could of course only look at the file Paths (old_path, new_path) in the Response

nginx - run shell/python script on wget request

I want to run a shell/python script on each wget to my nginx server.
For example, if I do wget http:///text.txt?example=100
I want to call a script that generates a new file called text100.txt, and returns it.
In other words, can I pass the GET params to the script, and return arbitrary files from that script so the wget client will download them?
Thank you!
What you're asking about is called cgi-bin.
However, I wouldn't recommend using it;
I would recommend against using shell scripts for web serving altogether, and
for Python I'd suggest one of the web micro-frameworks such as flask.

Difference between `protoc` and `python -m grpc_tools.protoc`

To compile proto files for Python, I could
protoc -I=.--python_out=$DST_DIR sommem.proto
based on https://developers.google.com/protocol-buffers/docs/pythontutorial
or
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. some.proto
based on https://grpc.io/docs/languages/python/basics/#generating-client-and-server-code
I wonder what's the difference between protoc and python -m grpc_tools.protoc, which one is more recommended for generating python *_pb2.py[i] files?
BTW, it looks protoc doesn't support --grpc_python_out.
protoc contains just logic for protocol buffers. That is, it will generate serialization/deserialization code for many languages. It does not, however, generate code for stubs and servers by default. This is left up to separate RPC systems through a system called protoc plugins.
Protoc plugins offer a simple interface by which an executable takes a description of a Protocol Buffer on stdin and outputs the corresponding generated code on stdout. Internal to Google, this system is used to generate code for Stubby. Externally, it is used to generate code for gRPC (or any other RPC system that wants to use protocol buffers).
Plugins get to register a command line flag for themselves to indicate where protoc should output the generated code. So, in your example above, --python_out indicates where the generated serialization/deserialization code should go, while --grpc_python_out is the flag registered by the gRPC Python code generator, indicating where Python stub and server code should be placed on the filesystem.
grpc_tools is a C extension bundling both protoc and the gRPC Python protoc plugin together so that the user doesn't have to deal with downloading protoc, downloading the gRPC Python code generator, and getting the necessary configuration set up to make them work together properly. However, in theory, you should be able to put all these pieces together to make them work just like grpc_tools (though I haven't tried).

How to upload files to gridfs lua module through nginx server, And which module should i use

I am trying to use nginx for serving static contents(images/css etc.)
I need to span up multiple instances of nginx to support as per the incoming load.
So i am looking for Mongo+gridfs solution to store the static files- since it provides replication and sharding.
I see i can serve contents from gridfs using either of these these modules.
Direct nginx module -
https://github.com/mdirolf/nginx-gridfs
Using Lua scripting language
https://github.com/bigplum/lua-resty-mongol
Question is - can i create UploadImage api in nginx itself to store files in gridfs when user calls a POST method passing the file.
It looks to me that it is possible using lua resty module but not sure. Any idea?
You can use the lua-resty-upload module to handle user uploads, and then pass the data over to lua-resty-mongol for writing to Mongo.
For large files you may be able to write the chunks directly as they are read to avoid buffering all of the data in memory, there's a good example on the page using a file.
I have used the upload resty module along with lua mongol module.. and it works well..
Now i got a suggestion from people around to see if we can use java. instead of lua to do db connections primarily to store retrive static file contents.
I see there is a Java module as well that can be used to do the job, or can use php or python as well in nginx.
Q is What would be the difference in using any of these languages- Lua vs Java vs PHP. and what factors should i need to consider while picking up a language.. Performance, solution usage, packaging, etc. Point of view

Checking email with CasperJS or PhantomJS

I'm looking to use CasperJS/PhantomJS to automate the testing of a project that extensively uses email as part of its process but I keep running into issues when I need check the content of emails in an automated way.
These tools are very capable of crawling through the HTTP version of many email services, but maintaining tests to keep up with UI changes made to external services is not something I want to do.
Do CasperJS or PhantomJS have the ability to use IMAP or POP3 to retrieve mail, or is there a more common solution that is generally implemented?
You can use any nodejs module with Casper:
"Like PhantomJS, CasperJS allows using nodejs modules installed through npm."
So you just need to check the npm repo and test which lib suits you.
Hi using casperjs\Phantomjs you can navigate and automate however for mailing process you have to use nodejs nodemailer module.Try the following command after installing nodejs.
npm install nodemailer#0.7.1.
This installs the nodemailer package and post that you can install the mail clients like sendgrid sendmail or you can just use the nodemailer direct transport but that may cause some delay in mail delivery.
Kindly check the nodemailer scripts and run the script using:
node scriptname.js
PhantomJS (and by extension, Casper) is a web browser - it's not able to use POP or IMAP as far as I know. My first thought as to approach would be to use a separate system for test automation (at least, for those tests that require verifying emails), e.g. using Python, Ruby, or Node.js, invoke Casper via the command line within those tests, and then use a separate tool to check and verify the email.
You could also use a dev smtp server with a web interface like mailcatcher (ruby) or maildev (node).
They also have a rest api, which returns the email in a more stable way than to use the web interface.
I don't tested it, but will soon.

Resources