How to implement middleware in Google Cloud functions framework in nodejs - node.js

I'm writing HTTP Google Cloud Functions using the framework provided by Google for nodejs based on express - testing on local for now. Samples don't provide an implementation of middlewares and HttpFunction type only has req and res as parameters. Is there a way to use middleware to handle authentication or body validation for a specific endpoint for instance ?

Related

Call google endpoint frameworks from node.js application

I need to call API's created using google cloud endpoint framework from my node.js applications. How I will be able to complete auth process and call the above APIs? Is it possible from node.js application to access the API's?
According to the official documentation, Cloud Endpoints Framework is a web framework for the App Engine standard (only) Python 2.7 and Java 8 runtime environments. It doesn’t support Node.js (nor PHP, Go) runtime environments.
=========================================================================
EDIT:
The answer to your initial question (“Is it possible from node.js application to access the API's”) is yes.
Your client application does not need to be in Python or Java, it can be on any language such as Node.js.
Regarding authentication, for the backend app (GAE), the flow would be the following:
You can authenticate the access to the Endpoints by creating a Service Account on Google Cloud Platform.
In the API Decorator, add the Service Account and public cert link.
In the API Decorator, add the SA as audience also.
Finally, on your Node.js application (client side), request Authentication by requesting the JWT token:
1.Create a JWT with the same audience set before on the API Decorator and sign it with the service account's private key.
2.Send the signed JWT in a request to the API.
Below you have some examples of the call request. I didn’t find examples in Node.js, they are in Python, but you can translate them to Node.js since the flow is basically the same:
1.JWT Authentication request GCP official documentation.
2.Accessing an API requiring Authentication (Python Client)
3.Github Google-Client-JWT Sample.

How to create nodeJS API with Firebase

I'm new to firebase part and I've one requirement to use firebase as a part of serverless architecture, below mentioned is something I need to do, can expertly guide me what to choose from firebase to achieve the same.
I want to create restful API using firebase with NodeJs with an express module of the node, is it something possible or any alternative way to achieve the same using nodejs?
I want to use the firebase authentication mechanism with nodejs code part, ultimately want to create API using the nodeJS with firebase to authenticate the user, so what to use from firebase to achieve the same?
There would be straight forward API that I want to create including the authentication and data store in cloud using firebase, here do I need to use either firestore or real-time database?
I want to deploy the nodeJs project using firebase with firebase cloud, can give me some more details on like how we can do that, reference link sharing would be appreciated.
I had a basic look into few stuff like firebase client SDK, firebase admin SDK, not sure in my case whether I would require to use client SDK or admin SDK to create restFul API.
Note: I want to use no SQL data base, where various collection I can create and can use the same using firebase, I checked that and firestore would perform the same thing, like to store the JSON data, but wanted to know is there any other way to store data or firestore is the best option?
I checked somewhere on reference link about the cloud function, this function can be triggered based on some event, including some https request trigger as well, wanted to confirm using cloud function to create restful API is the good approach or what is the best way to create API using firebase.
I want to create restful API using firebase with NodeJs with express module of node, is it something possible or any alternative way to achieve the same using nodejs?
Yes it is possible
I want to use the firebase authentication mechanism with nodejs code part, ultimately want to create API using the nodeJS with firebase to authenticate the user, so what to use from firebase to achieve the same?
You can use firebase SDK for authentication
There would be straight forward API that I want to create including the authentication and data store in cloud using firebase , here do I need to use either firestore or real time data base?
If you are asking of the database, then you can use any database of your choice, wheater it is MongoDB, firebase-realtime-database etc

How to get data from Secure REST API in lambda for Alexa skill?

I am creating a Alexa Skill that will get data from BPM tool.
My BPM Tool provide a secure rest api that we can invoke with basic auth like username and password.
How can i call this type of web api in node.js code created in lambda?
Steps:
1) Create Amazon API Gateway api for alexa and deploy into stage
2) Write lambda to work with Alexa Skill
3) Call your API end poingt into your node.js
https://github.com/alexa
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs
If you are worried about credentials, you can set those up as environment variables for your lambda.
With that out of the way, you should be able to use any http library (like axios or needle) to make the requests to the service.

GCF with passport JS

We are trying to use cloud functions, but we are struggling with authentication.
On our node.js application (running on GAE) we are using Passport.js
Is it possible to use the same mechanism for GCF to authenticate the requests?

Parse Server Express Routes and Auth

I'm using Parse Server and I have an external client that will make calls to my Parse API using a rest client. This client will be using the Parse JS lib and will be authenticated.
I can't expose the Parse Rest API cause I have a lot of business rules to check in other MongoDB database before return the response.
Can I create custom Express routes that are authenticated by Parse without cloud functions?
Parse Cloud Express helps but as I have a lot of business rules I'm looking to keep it as Express routes.

Resources