Deploying springboot app and ui separately - java

Currently, I have a springboot jar file with a bunch of rest and apis including calls for login deployed on ec2. I also have a separate code base for my ui i.e with js,html,css. What is the best way to deploy this on aws and keep it separate from the backend.

This can be done in many ways. But will share a simple way.
Deploy your spring boot app in one aws instance.
Deploy the other front end app on the other aws instance.
This is a kind of two tier application where the server and client app are hosted in different instance. You can restrict the access of your rest api to be accessed only by the instance where you host front end app. For trial you can use heroku account. E.g.
Github: https://github.com/krishna28/springbootapi
Also check https://github.com/krishna28/etodo

Related

How to run an application that uses aws Service Discovery locally?

I'm currently trying to create an application that have some separated micros-services and they need to communicate between them.
The problem is: I want to deploy the complete application to aws, using ECS, ECR, and mainly using AWS Service Discovery.
The application runs ok on the cloud, but how to run it locally?
My initial thoughts tends towards something like choosing between using the Service Discovery when on the cloud or using something like Eureka locally.

Angular2 frontend Spring Boot backend on Google cloud platform

I have an Angular2 front-end and a Java Spring Boot back-end with my REST endpoints.
Now I want to deploy this app to Google cloud platform, but I want to keep my projects separate.
All I've read is about deploying one single application, but I want to keep my front-end and back-end separate.
How can I deploy my separate projects to Google cloud platform and have them communicate here as well?
Thanks for your help!
The easiest way to do this in GCP would be to host the frontend in Cloud Storage and set up your backend in Google Compute Engine (GCE) or App Engine.
Frontend
Cloud Storage provides static hosting capabilities. You can upload your frontend files to a Cloud Storage bucket and configure your domain to serve content from that bucket. Here is a tutorial for setting a bucket up for static hosting.
Once your backend REST endpoints are set up, the frontend app can easily communicate with them using Angular's AJAX capabilities.
Backend
If you prefer direct access to the machine your server runs on, you can upload the backend code to a GCE instance and run the server there. Otherwise, I would recommend deploying the server using App Engine, which will manage the instances for you.
One point you might be interested in is configuring permssions for your backend endpoints. If you want to restrict access to those endpoints and only allow your frontend to communicate with them, try out the Google VPC firewall features.
Good luck!

spring boot application in cluster

I am developing a spring boot application.
Since spring boot created a .jar file for an application.
I want to cluster this particular application on different server. Lets say I build a jar file and ran a project then it should run in cluster mode from number of defined servers and should be able to serve end user needs.
My jar will reside on only one server but it will be clustered across number of servers. When end user calls a web service from my spring boot app he never know from where it is getting called.
The reason behind clustering is suppose any of the server goes down in future, end user will still be able to access web services from another server. But I don't know how to make it clustered.
Can any one please give me insight on this ?
If you want to have it clustered, you just run your Spring Boot application on multiple servers (of course, the JAR must be present on those servers, otherwise you can't run it). You would then place a loadbalancer in front of the application servers to distribute the load.
If all services you are going to expose are stateless so you only need to use load balancer in front of your nodes for ex. apache or nginx, if your services are stateful "store any state [session, store data in db]" so you have to use distributed cache or in memory data grid:
for session you can use spring-session project which could used rails to store sessions.
for store data in DB you need to cluster DB it self and can use distributed cache above your DB layer like Hazelcast.
Look into spring cloud, they have used some netflix open software along with amazons to create 12 factor apps for micro services.
Ideally you would need a load balancer, service registry that can help you achieve multiple instances of spring boot. I believe you have to add a dependency called eureka.
Check the below link
Spring cloud
You can deploy it in cloud foundry and use autoscale function to increase your application instances.

What are some techniques for deploying a single page application that depends on a rest api?

I'm building a Single Page Application (using AngularJS) that renders data from a REST API call it makes to a legacy system. This legacy system is very large, written in Java and takes minutes to deploy so we decided it would be more productive to develop the Single Page Application completely separate from the legacy system.
The problems occurred once we tried to communicate with the legacy system's REST API. Although both apps were deployed locally to the same host, they were deployed on different app servers so I needed to use different ports when communicating. But because the SPA was communicating to a REST API on a different port, the browsers prevented my requests to protect against Cross Site Scripting attacks.
We found this build tool name lineman (that leverages grunt) that made it easy to proxy http requests. This got us around the cross site scripting limitation but this was only suitable in development mode.
Now that we've got a proof of concept working, we want to know how we're supposed to deploy these apps together without the proxying. It's hard for me to find advice on how to do this because Angular doesn't assume you have a backend in the first place and most people that use Angular on the front end aren't using Java in the backend (if that even matters).
We're running into issues like, the context paths of the apps change depending on if they're deployed in prod mode vs dev mode so we've gotta think of clever ways to avoid broken links that work for both modes. I wonder if/where I took a wrong step here along the way. Should I avoid developing the SPA on a separate server from the backend?
We had the same issues. The URL situation is that you will have different URL paths to your java REST API because you are in different environments.
In order to make these paths cascade down to the angular application, we had to first externalize the base paths in the web app (the app that spawns Angular) to use values that are set during deployment depending on where it is deployed to. We have values in our app servers that link to XML values in config files that we then reference in the application.
Then we create a call from the Angular app to the webapp that spawns it (not the java REST API) that will return the URL that is correct for the environment.
In the angular application, we can then setup the resuorce with the correct base path (the rest of the URL should stay the same from environment to environment).
If you can get the first part working correctly with externalizing the environmental settings, the rest is not difficult.
I would put apache in front and use mod_proxy as a reverse proxy to the apps.
Say your REST API is at http ://localhost:9000. If the angular app is only static assets you can deploy it directly under apache. If not you reverse proxy it as well.
For the REST api yoivsetup a reverse proxy for say /api to localhost:9000. So any request hitting the apache at http://some.host.name/api will now be forwarded to the legacy system. Now fix the angular app and you are done.
For local development you can use node-http-proxy which is ease to setup in a similar fashion

Running a java application on a remote server

I want to run a standalone java application on a remote server. It would not be accessible to clients, but would do background calculations and interact with a database and Secure Socket connection to a third party site. It would also interact with a php site.
Do I have to deploy this with JSP, or can I write a standalone application? If so, how would I deploy a standalone java application (jar file) on a remote server? I understand that I must have them install a jvm on the server (not a problem) but then how would I deploy it (if possible). Would I start it with a command line?
I know I have much to learn, but I am not sure how I would access the command line on a remote server. Through the cPanel?
Thanks.
First of all, you'll want to set up some firewall rules to allow access to that server. I'm hoping that you don't expose that server naked to the Internet.
If all you need is database access exposed on the Internet, I don't see why it can't be a secured web app deployed on a servlet/JSP engine and accessed via a web server. You can leverage basic auth for security, JDBC access to the database from the server, and servlets as controllers to accept requests in a nice REST API.
It'll save you the complications of sockets and inventing your own protocol (use HTTP), starting and stopping the application (now it's just a web server/servlet engine), and deployment (send a WAR file).
Does it really must be a 'standalone' application? I think that in your case the best match would be to use Spring container to load your application within some server (tomcat?) and expose services via standard controllers - with Spring you only have to add some annotations on services methods actually.
Then, your php site can interact with these controllers using for example ajax requests.
If your application is written already, you can easily transform it to run within Spring container. It's very non-invasive and promotes usage of POJOs.

Categories