Angular 2, Spring Boot, Spring Security, Login Form

I have a Front end application that runs on http:// localhost:4200 , with angular 2 (I used angular-cli to create the project).
The application works without problems (I can receive and send information from / to the database using the angular 2 Http :

 getList () { return this._http.get("http:// localhost:8080/").map(res => res.json()); } 

On the other hand, I have a Back end application running spring boot on http:// localhost:8080/ (note the ports) that provide REST Api for my angular 2 application.

Sending requests from http://localhost:4200/ to http://localhost:8080/ works as expected.

Before I programmed the application with the spring framework, and the angularJS 1 function, spring took care of the login and security in the same application (maven project).

Now I have two separate applications that communicate via Http (RESTful Api with spring boot and Api frontend with angular 2)

How can I set my registration form and where to place it, and how to configure spring security with my angular 2 application?

+6
source share
1 answer

When you deploy an Angular application with the Angular CLI, your Angular pages are served by NodeJs in the backend. You have a couple of options.

  • The input can be processed on the NodeJS server, which, in turn, can cause Spring Download the application for authentication and authorization (I think you may need to make some settings, such as using the express server rather than the Lite server. Look here fooobar.com/questions/1010973 / ... )

  • After the initial development, you can copy your AngularJS resources to the Spring MVC server (Spring Boot) and use it to serve your pages (like the rest of the APIs), just like you did before.

  • Create an Angular application to call Spring's boot service (I think you use $ http.post to submit the form, if this is the case when you can just change the URL so that it can get into the Spring application to load.) To deploy production, use nginx / httpd to serve static files (AngularJS / CSS, etc.) and route / proxy all dynamic requests Spring boot application.

I would strongly suggest the third option.

+3
source

All Articles