Setting up webserver to test webhooks api via Jenkins - node.js

I am executing a bunch of postman APIs using Newman command on Jenkins.
One of those APIs requires a webhook URL in the body:-
{
"webhook_url": "http://localhost:8000"
}
which I want to use later on to retrieve the content posted on it.
I tested it on my local machine by creating a local web server using nodeJs which acted as a webhook URL and I could verify/see the content getting echoed on that web server.
But I need help on how to achieve this same thing via Jenkins.
In short, I want to:-
Create and Start a web server via Jenkins which I can use as webhook_url
Execute collection of postman APIs and verify content posted on webhook_url
Kill web server

Fixed it by creating webserver image in docker so that I dont have to create, start or kill it via jenkins.

Related

NodeJs + Puppeteer on Azure App Services fails to run

I've wrote a simple NodeJs (ExpressJs) server that uses Puppeteer to generate PDF files on JSON data being passed to it. While locally everything is working like charm, I'm struggling to run this server on Azure App Services.
I've created a Resource group, within it I've created an App Servces instance (running on Linux) that is connected to my repo at Azure DevOps (via the Deployment Center).
My server has two endpoints:
/ - returns a JSON - { status: "ok" }. I'm using this to validate the running server instance.
/generate-pdf - uses the Puppeteer to generate and return a PDF file.
After successfully starting the App Service instance I'm able to access the "/" route and get a valid response but upon accessing the "/generate-pdf" route the result is "502 - Bad Gateway".
Does my instance require some additional configuration that I haven't done?
Does App Services can not run Puppeteer? Perhaps there is a different service on Azure that I need to use?
Is there a way to automate the process via the Azure DevOps pipeline or release?
Any questions/thoughts/FAQs are more than welcomed. Thanks =)
I'm answering my own question: as was mentioned here https://stackoverflow.com... the Azure App Services does not allow the use of GDI (which is required by Chrome) regardless if you're using Linux or Windows based system. The solution was to put the NodeJs application into a Docker container and manually install Chrome. Once you have a container - just upload it to the Azure App Services and viola!
By default App Servies exposes 80 and 443 ports, so if your application listens on a different port be sure to specify it via the WEBSITES_PORT environment variable.
In my case, I had to upload the Docker image to the Docker hub but you can also set up a pipeline to automate the process.
I've built the Docker image on my M1 Pro and it led to some arch issues when the container was uploaded to Azure. Be sure to add the --platform linux/amd64 in the image-building step if you're building for Linux.

How to get a post request from Azure web app

A sprint boot rest api is deployed as the web app via fire up a docker image in Azure. After that I need to make a POST request to test the API. Here comes the issues. I seems can't access the API. It is not the issue of the code itself since I can get the result if I deployed the code locally,
Here are some of my key steps
I add the following user command when fire up the application from the docker image (docker image is saved in the azure container registry)
docker run -d -p 8177:8177 my-api-image:latest
login to azure from azure-cli
az login
I query the post method in the terminal
curl -X POST -'from=161&to=169&limit=100' https://<my-app-name>.azurewebsites.net:8177/readRecords
But I am keep getting the Connection time out error
Failed to connect to <my-app-name>.azurewebsites.net port 8177: Connection timed out
I also try to run the curl method from the shell from the Azure Portal in the browser, it also told me the time out error Anyone know the reason of this? and how can I solve it so that I can send a post request.
Azure web app only support http 80 and https 443 port.
So your port 8177 doesn't work. For more details, please read my answers in below posts.
Related posts:
1. Strapi on Azure does not run
2. Django channels and azure

Run a Firebase Testlab test from node server

we have a Heroku hosted nodejs server that servers a rest API. We want to add an endpoint to which we can upload an APK and have the server spin up a test for us on Firebase.
I can't seem to find any nodejs server side libraries from Google to help me achieve this.
In your nodes server, you could call Cloud Testing API directly to start a test. Test execution results can be retrieved with Cloud Tool Results API. Both of these two APIs are public API and there is Nodejs client support.

authenticate to Google Cloud Platform from a Linux Server

I have developed a java program that involves API connections, DataFlow pipelines and BigQuery to load data.
Locally in my computer it works fine with GCP authenticator and running pipelines in the cloud.
But when I run a class in the linux server it ask me for authentication but with an url.
this is the output in the server
I tried "gcloud init" sending credentials but it still asking me for authentication.
has anyone faced this situation?
thanks!
Your application is attempting to use OAuth 2.0 Flow to obtain credentials. Since your server does not have a web browser, you are given a URL to go to in your browser. Once you do that you will receive a code to copy-and-paste back into your server.
The solution is to change your program to use Google Service Account Credentials.
This link has a detailed explanation and code examples including Java.
Setting Up Authentication for Server to Server Production Applications

Run Phonegap applicaton with node-express

I wanted to make mobile app from existing webapp. My webapp is nodejs-exressjs REST API server, with HTML/JS client.
I wanted to leverage API from my REST server, and swap out client with phonegap/cordova based mobile app.
Till now, the only feasible solution seems to be use CORS, and have phonegap/cordova server and nodejs servers running separately.
Is there a way I can use same server to deploy both my REST Server, and Phonegap/Cordova Client ?
No sorry, Cordova apps rely on having the front client in local, and perform calls to server in REST, so your first thought is correct. You can share the REST server for both applications, but the code of the cordova app client is going to be in the devices locally, without need of a server.

Resources