Hosting a REST Composer Server Online? - node.js

Till now I was running the Composer REST Server (Blockchain) locally on the local host server. Now this server has got some post APIs configured which needs to be triggered by my main server already hosted on Heroku(Cloud Service).
So the flow of architecture is like my Android App calls Heroku Server which in turn has to call the Composer REST Server (which is running locally on my machine).
Hence I need to host the composer REST Server on a free tier cloud service. Although its a Node JS Server but it's package.json is weird and I am not able to find any resource which specifies how to take the Composer Online.
Please help!

Is your underlying Fabric is running in Docker Containers?
Assuming that it is, you can run your Composer REST Server in a container too. There is an example of this in the composer documentation for Multi-User mode which makes it look a little more complex, but the import piece is getting the Card in the container. There is also a Tutorial in the composer documentation again for multi user mode.

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 run a node server in an azure virtual machine permanently?

I build a web based mobile app (using react), which I'm hosting as an Azure Web app. This website is connected to a node server, which I'm hosting using a azure virtual machine (I don't know if this is the best approach, maybe I should host this as a webapp instead of VM ?).
I'm still new to this strategie of developing a web based mobile app and connecting it to a hosted backend in the cloud so I apologize if this is a trivial question.
I'm using websockets to connect my frontend to the node server and then I consume messages. I don't have a database it is a simple application.
The steps I'm doing to run the app are:
I connect to the Azure VM from my laptop with ssh
run my server using node server.js
When the server is runing, I can refresh my website and everything works fine
Now, the problem is that I want the node server to run all the time. However, I noticed that the server stops running when I deconnect (ssh) my laptop from the virtual machine. So I find myself doing these steps (connecting to the VM with ssh and running the server manually) each time I want to use the app.
Is there a way to do this so that the node server runs all the time without stoping? Also since I'm new to this, is this the right way to deploy frontend and backend? I assume I can't deploy both frontend and backend in the same Azure webapp or am I wrong?
(Since part of your question is around "Is there a better way?", I would answer that instead of fixing the issue in your current VM hosting :)).
To take full advantage of cloud for your applications, PaaS is always preferred over IaaS. In this case, unless you have any specific reason, you should deploy your backend Node app in another App Service (aka Web App). Or you can consider Azure Function also if your node app has a small set of APIs, but it will require code update. Both support multiple platforms including node.js. Since you mentioned you are leveraging Web App for your react mobile app, so I hope you are already bit familiar with it. Also since Azure Function would require code change, so Web App is preferred this case.
Note: I omitted other solutions like AKS, Service Fabric etc. for now, since currently we are talking about the problem of deploying only a single app, for which those will be overkill at this moment.
Also, to your point
I assume I can't deploy both frontend and backend in the same Azure webapp or am I wrong?
Yes technically you can, depending on your scenario by "bundling" into a single app if both are in same platform (like Node in this case). Though whether one should do that would be an opinionated answer. But even if you keep those separate, you can still leverage single App Service Plan for cost saving. So keeping separate like you have now is what I would suggest to maintain "separation of concern".

Changes made to REST server using APIs not reflected in Composer Playground?

I have defined a Business Network, installed and deployed it on my local machine. I have also create a local REST server for testing. When I am submitting transactions through API calls, they are reflected in the REST server (which I can verify through GET requests on the same APIs) but not being reflected in the Composer Playground 'All Transactions'. Where am I going wrong ?
Composer-playground only provide easy access to the hyperledger network.
So, if you made the transaction REST-API, than you can see the same transaction in local playground also and vice-versa.
So, check that you connected to same business-network in playgroud.
Run composer-playground command, connect to network installed, that's it.

Deployment of block chain in cloud

I have create cordapp in azure VM. now i want to deploy that cordapp into Azure cloud server so that client from anywhere can hit cordapp. but i confused whether i have to use webapps or inbuilt Blockchain module in marketplace. if so, how to do deploy?
You can deploy a node to a cloud server by following the instructions here: https://docs.corda.net/deploying-a-node.html.
You can then interact with your node remotely, using either:
An RPC client (e.g. https://github.com/corda/cordapp-template-java/blob/release-V3/clients/src/main/java/com/template/Client.java)
A server (e.g. https://github.com/corda/cordapp-template-java/tree/release-V3/clients/src/main/java/com/template/webserver)
The node shell over SSH (Corda V3 onwards - see https://docs.corda.net/head/shell.html#the-shell-via-ssh)

Deploying NodeJs to Service Fabric Cluster

Has Anyone had any experience to deploy a RESTFul nodejs service to service fabric?
What tools are possible, Jenkins or even code ship
Found a knowledge base article from Microsoft here, looks like you just package it up and drop in into a folder location for Service fabric to consume
https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-multiple-apps
To deploy a RESTFul node.js service to service fabric you need to have a Node.js host - to actually run your JavaScript. There are three options for that:
Create custom executable and deploy it as Service Fabric guest. Example: https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-multiple-apps
Use Dicker containers on Service Fabric: https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-tutorial-package-containers
Use SupercondActor to host Node.js API natively inside Service Fabric stateless service. See GitHub repo: https://github.com/SupercondActor/platform-app-angular

Resources