6

Please correct if the way I am doing is wrong.

In my web application I am not using jsp pages for developing user interface. Instead I am using html, css and Angular 2 and front-end project structure is separated from back-end.

Although I am able to develop a simple project using Angular CLI which is served by SpringMVC back-end. Front-end is using port 4200 and backend is running on port 8080. I have managed to take and serve request from Angular 2 to SpringMVC. In local mode these are working perfectly, now I want to make them host on a live server.

How to publish SpringMVC back-end and Angular 2 front-end separately but running on same domain? I am not using SpringBoot also front-end and back-end are in separate folders. I do not want to combine both in same project structure and generate a war file and deploy.

What is the best practice for developing SpringMVC back-end and Angular-2 back-end and deploying them in online server?

2
  • What you used for packaging the Angular 2 App? Which server you are using for deployment? Commented May 18, 2017 at 11:30
  • I have used webpack for packaging the Angular 2 App. Is it possible to deploy both back-end and front-end which are separate project in same server with same domain name? I do not have prior knowledge of deploying web applications. Commented May 18, 2017 at 15:31

1 Answer 1

1

What I've found works best is running nginx as a static file server and a forward proxy for the spring app.

usually I use the angular-cli proxy to make /api/ go to http://localhost:8080

that means that calls to http://localhost:3000/api/** get passed to http://localhost:8080/api/. And since you are on the same domain we can simply call /api/

Sign up to request clarification or add additional context in comments.

2 Comments

That is already running fine for me. But can you tell me best procedure of deploying front-end and back-end in online server. As far from my knowledge after reading different blogs, they have suggested not to create a single war file combining both front-end and back-end. How to host front-end which is making request to SpringMVC back-end?
If you are using spring boot create a runnable jar file and launch it using systemd docs.spring.io/spring-boot/docs/current/reference/html/… now you have spring running on port 8080. now install nginx and create a nginx configuration that uses proxy_pass to send all requests for /api/ to spring. then ftp or rsync your angular files into the server and use nginx to serve them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.