How to decouple JHipster frontend from backend - angularjs

I'm trying to figure out, what needs to be done in order to have the HTML/JS on my webspace (HTTPS and CDN) and the backend on my application server (TOMCAT). I can't find a global variable to do this, do I really need to change all AngularJS factories?
Cheers,
Daniel

Related

Common way to build and deploy a react web project

I finished a part of my project and bought a webspace with a domain and a database to publish on. So I create a React-Typescript project with followed structure:
API: has my controllers
BLL: the services
Question do I have to create a Build and publish it on the webspace, with the API, BLL... or only the Web component? So that the API, BLL... are on a seperate server and the fetches from the Web-Component are via IP:Port address?
What is the common way here?
The in and outs of web hosting is massively large problem space. And the strategies and approaches number in the thousands. I couldn't hope to do justice to that in a single answer. But in short, you probably want them on the same server, and you want your backend to deliver your front end assets to browsers somehow. And your frontend makes requests without a domain like /api/mydata/ to pull data from the same domain as the frontend. This question will likely get closed now, as it's way too broad to answer.
– Alex Wayne

Can I build a CoreAPI JS client from DRF and inject it into a react project

I'm building a React client and a REST server with Django REST framework, neither of which are something I'm particularly good at.
Anyway, on the client side, I find myself writing various calls to fetch, and managing the endpoints and content types, which seems dumb.
I noticed that I can use CoreAPI to build a schema of my API and somehow automagically make an API client.
Can I, and would it be sensible and straitforward, to somehow autobuild that client and inject it into my app, and then call it.
This sounds nice and feasible, but not sure how to go about it, thoughts?
Thanks.
The best library I have found for writing js client for DRF is https://github.com/tulios/mappersmith

How to make Ionic app work with an API written in Laravel but still works offline

I would like to ask how to create an ionic app that talks to Laravel API but still works offline when there's no connection.
Let's say i have to write a quiz mobile app in Ionic and it requests for Laravel API to retrieve the questions as well as store the scores in db.
I'm just starting to learn Ionic and i'm really confused right now on how to approach this.
What confuses me most are:
Does the Ionic source live inside the Laravel source code w/c serves the API?
If i want the Ionic app to be installable, should the Laravel source code be included as well during the compilation process?
Thanks in advance for any help.
Your php or in general server side code is completely independent from your ionic application. If you want your app to work offline you should think about something like fetching a high number of information initially and work with this data without making any additional requests.
However your ionic app does only contain the frontend. You could implement some logic for local storage, but if you want to keep information hidden from the user (e.g. solutions) you have to put that logic on a dedicated server.
In the few details you provided, I can say the Laravel code does not live inside the ionic app. The ionic app is separate from the backend API by Laravel. You are possibly trying for a ReST based architecture where you communicate with your Laravel Server with an API. You need to keep those codes separate.
However without any internet, you won't be able to access those APIs, so you will just be able to show some static data, or you could serve from a DB and show later. For how to use the sqlite db you can look here
In your backend you can have an API like
http://example.com/api/v1/questions/1/
Which will fetch a question with options and if you want the app to have the answer for offline storage you may have that as well. When a user answers, you may check whether you have internet access and send answer and verify if you do, else you may save the answer in your DB and sync when you do have access. You can fetch multiple questions so that a user may answer multiple questions in case he/she will not have internet access.
Hope it helps. :)

How could I centralise AngularJS configuration when part of an ASP.NET MVC project?

I have an AngularJS SPA served up as part of an ASP.NET MVC application. Within this I have an Angular factory which accesses a REST API elsewhere on our intranet. We have various instances of this API for development, production and UAT. I'd like to be able to configure the URL of this API within something like the web.config so that when I build each different solution configuration the correct URL is provided to the factory.
Unfortunately I'm working within an environment where I cannot use npm (it's complicated - suffice it to say that NTLM proxy authentication combined with a smartcard login don't play nicely with npm), so a lot of front-end build tools that seem like they might have been helpful aren't available to use.
Currently I'm just thinking of adding a method on a controller which returns a value in the web.config, but this doesn't seem terribly elegant. Perhaps there's a better way?

Microservices communication/deployment

I read a couple of posts and presentations on Microservices concept and architecture and REST, and was unable to find answer to a few basic question.
If service A depends on service B, how does sevice A knows where to find (host and port) service B? I'm guessing hardcoding isn't very nice.
If I have, for example, an AngularJS client which request multiple services deployed, how does the angular app knows how to find those multiple services? Again, hardcoding doesn't sound right.
Thank you in advance
AngularJS has Dependency Injection baked in. Use that to construct your dependencies.
If you wanted to reduce the "hard-coding" further, I suppose you could deploy a "Service Registry," which could maintain all of the dependencies. You could then call the Service Registry service to get the port numbers and such, and maintain them in one place. Seems to me like overkill, though.
This is more of a Java based solution to your problem, however it is a very proven method. Take a look at Spring Cloud / Netflix OSS. The Spring Cloud project has a working example on github using AngularJS and the various backend services that make up the Spring Cloud solution.
Specifically the following:
Eureka -> Service Discovery, solves the problem of host and port
Zuul -> HTTP Proxy, solves the problem of finding the current host and port via Eureka integration. Zuul can help with security, CORS etc.
Another possible solution is Zookeeper. I have no experience with Zookeeper.

Resources