How to request a Node.js code execution on the client side? - angularjs

I have an Ionic Framework app (v1) and a Node.js file that executes some functions to a credit-card API I'm using. I've been testing the execution of the node file with the following command on terminal:
$ node file.js
And it works perfectly with my local machine. The problem is that I'll use my app for production soon, so how can I run this server-side code after a button click event in my front-end app ? Do I need to store this node file in the server and access it with angular http service ? How can I trigger the execution remotely?
I'm currently using Firebase as my back-end.
I've been struggling with this for days and I'm pretty new to Node.js. Please help me.

In terms of architecture and best practices, I recommend you to create an NodeJS API application and your Ionic app will make request to this API. You need to define route(s) to your NodeJS app, put it in production to provide Ionic app to send requests to its route(s).
As you sad that is a simple function, look at Express that is a NodeJS framework. The routing guide shows how to create a simple route using this framework.
To summarize, your Ionic app will send requests to NodeJS API route and this route will execute some functions to your credit card API.

Related

React app / UI communicating with backend services (spring boot - micro services) thru express / node server

I'm working on a project where the UI is built with React Js. The communications with backend micro services (spring boot) go thru node / express server. The react app's using Axios HTTP client library .
The react does not directly call micro-services' rest api endpoints, but calls the api endpoint of the express server and the the express calls the micro services's endpoints.
communication: UI(using Axios) --> express server --> REST endpoint.
I am curious why the react app does not directly call the backend api using the Axios and it has to go thru the node / express server.
is this an ideal design of client-server application or might there be other valid reasons for this. I would really appreciate and many thanks in advance if any explanation / if anyone can shade some light on this. Thanks! enter image description here
I have also attached the screenshot of the folder structure. src/client - contains react code and src/server - contains nodejs code that communicates with the micro services endpoints .
I tried to trace the call from the front end to express to backend micro-services, but not quiet 10 0 % clear about the client-sever communications.
For the project you're working on, it might go through the express server for some type of data transformation or applying some custom headers. And then express server makes the call to the Spring Boot application.
Tough to know what it does without actually seeing the code. In my current application, it goes to our Spring Boot application and then forwards the request to our Lambda microservices. We use the spring boot application to apply custom headers and some other miscellaneous things.

React consumes API in development, fails after deployment

please help me with the following problem as it already taken me so much time to figure out:
I have an API which I created using PHP and hosted with AWS EC2.
This API is to be consumed by a React frontend app I made, and when I am developing the frontend there are no problems sending and receiving data from the API.
However, after I deploy the app using AWS Amplify, the app loads correctly but fails to connect to the api(i.e. not showing fetched data, unable to post forms)
I read a little bit about proxying but I am not sure it is the solution and if so, how would I implement it.
Thanks a lot in advance.
I resolved the issue.
My problem was that the server was not listening to https port, so the browser blocked the content.

Is there a way to run react Application on SpringBoot and to in Kubernetes?

I am running the React Application on Spring Boot which runs as containers in Kubernetes. When the react application interacts with the backend through REST, It should resolve the dns of the REST URI.
I have tried directly giving the service name(i.e. while calling the REST API from react application i have given the https://service-name:port/api/v1/test/), but it is not working.
In case your backend is on another namespace use the following format:
<service-name>.<namespace-name>.svc:port
For a Kubernetes service demo-ser on demo namespace the URL will be something like:
https://demo-ser.demo.svc:8080/

How to use API as backend in ionic mobile app development?

I am having a web application built using JAVA spring which has API feature to read and write into database.
Now i have to develop an ionic mobile app for the same application. How to read and write data into database.
I know Firebase and other alternatives can do the job.
But i need my own API code(written for web app) to be used. Is there any way to achieve that?
I guess calling the respective API when the web application is live is achievable.
But how can i achieve that while developing(When the web app is under construction)
Well depending on how you set up the API this could become quite difficult.
You're saying/guessing that you can call the API when the webapplication is live. This makes me assume you've created a REST API? Or did you create a Spring MVC application?
If the webapplication is directly linked to your Spring application (f.e. going to localhost:8080/my-profile shows a page (not JSON) of your profile) then I'm not sure if you can achieve the above mentioned target.
If you get a JSON response, or are somehow able to retrieve it from the webpage, you can just simply call (in typescript:)
this.http.get('http://localhost:8080/my-profile').map(response => console.log(response.json() );
Else, you probably will have to create a basic REST API (check out Spring boot for a 5 minute setup) and provide it, either with hardcoded data or connect it with your database.

App Engine works when access by version specific url, but not by the main url

The Problem:
I can access my Cloud Endpoints API via the following version-specific URL:
https://[version]-dot-[myappid].appspot.com/...
but I can't access it via this main URL:
https://[myappid].appspot.com/...
the error I receive in the chrome console is this:
https://[myappid].appspot.com/_ah/api/discovery/v1/apis/userEndpoint/v1/rpc?fields=methods%2F*%2Fid&pp=0 404 (Not found)
What I've done:
First off let me say I'm very new to App Engine so apologies if this is a silly question.
I've created a Google Cloud Endpoints Backend module as part of my project in Android Studio (v0.5.6) which uses all the new gradle stuff and Objectify annotations.
I've tested my back end locally on the dev server and it all runs fine.
I then deployed it to appengine using the gradle task appengineUpdate and all went well.
I deleted previous version instances running in my app engine cloud console and made the newly deployed version (version-2) the default.
I can access and use the endpoint API fine via the version specific URL as described above but not via the main url.
I have a simple index.html file which is using the endpoint via the javascript client library to test with before building client libraries for my android app.
On both versions of the URL the index.html file renders properly, it just can't connect to the API.
If anyone knows how I can get the app to run properly on the main URL (or let me know if it's not supposed to) that would be awesome!
Many thanks!
Solution was to use appengineUpdateAll which calls both: appengineUpdate and appengineUpdateAllBackends my bad!

Resources