I am trying to integrate java backend with front end angular js ui.
I copied the ui code in web-inf folder and trying to show as on load of my dynamic project but I don't know how to serve static page in this web app.
Please help on it. Either I have to write something in index.html or WEB.xml file?
Well, here is my 5 cents,
Angular js is UI Framework and it should be mounted in HttpServer (node js?)
Where as Java is backend and you need to expose it as Webservice and host in web server.
I think you are using REST to consume your service in UI.
Related
I have a question about how to integrate Angular with NodeJS and Spring Boot.
I have developed an application with Angular as UI and Java/Spring Boot as backend REST API. The problem is that SEOs in a SPA do not work well. For that reason, some developers created Angular Universal to render Angular applications on the server side.
Unfortunately, Angular Universal works only with ASP.NET or NodeJS.
Some attempt was made to make it work with Java as well, (see: https://github.com/swaechter/angularj-universal), but the repo has been archived/abandoned.
If I understand it correctly, the approach would be to run a NodeJS server that is in charge of rendering the Angular UI server side only, while the java service would be in charge of exposing the REST API, but since I have no experience with NodeJS or Express.js, I am not sure if that's the right way to proceed and what implications should I be care of. I couldn't find any guide online.
But my question is, should the code in angular make requests to nodeJS and then nodeJS forward them to the java service, or should angular contact directly the java service to get the data, and only NodeJS to do the SSR?
Thanks
If I understood you correctly, what you are trying to do is called prerendering an Angular application, AFAIK Angular Universal uses NodeJS to do that.
An Angular application is usually compiled to vanilla JS that the browser can understand, which means that in build time you could compile the parts of your application that are static (aka "known at build time"), this is done by NodeJS. This has a problem, if your static parts use browser facilities (e.g. localStorage) or call backend services you have to wrap them with:
if (isBrowser) {
localStorage.set('example', 5);
fetch('example.com/service');
}
In your pipeline you have to build the project and move the generated JS, HTML and CSS to be served directly through your application server or proxy if you have (e.g. nginx).
Here I have an example of a real project that you could take a look that do prerendering with Angular js and Spring Boot. In this project the angular application is served through Spring Boot. https://github.com/afdezcl/kemenu-web
Currently, I develop with java / spring-boot / log4j2 , and as much as I have searched I have not seen anything interesting to log directly to a web page in real-time (something like swagger style with requests, which is by configuration without having to write code) .
Do you know anything?
You need Javascript to modify the DOM of a webpage, not Java.
You could use Spring to send Server-Sent-Events (SSE) to a frontend JS library, or host a WebSocket or other REST API on some web server and use AJAX to issue requests, upon which the DOM is modified as part of a response, but this really has nothing to do with Java/Spring/log4j
If you want a packaged distribution of Spring w/ some Javascript framework, JHipster is a popular option.
I want to create a Spring MVC rest application for web browser, android and ios
For web browser, I am using angular2 and my web server is apache tomcat.
So I am confused that I need to put the angular code inside my Spring mvc appllication project directory or create a separate instance for angular.If I have to create separate instance for both then how I will deploy angular code to the tomcat server.
You can do the both.
If you want to put the angular2 files to the tomcat then look here. This is might not straight forward.
If you want to deploy separately, I mean server(spring REST) and client(angular2) then angular2 app can deploy using the ng command or any web server like apache, nginx. You can look here for example
You can do that in any of the ways.
But
with a SPA + REST technology stack, I prefer separating front end and
back end with rest api because static resources are best served from front-server. Since Front-End servers (e.g. nginx,apache2) are very powerful and since you can use Cache for static resources, you can manage with a single deployment of your static resources (which should be all HTML content, JS, CSS, Images).
I'm trying to create an application using Angular js & Spring Framework.
Now I'm confused what will be the best way to create the spring app??
Using Regular Spring web Application with Jsp and integrate the Html code for angular in jsp and view Resolver?
Using any Generator (likely to have npm spring-angular generator).
Create new angular app and redirect the / to the angular application and change code in angular and server side will be only REST ?
I think the third is the good way. Doing Spring REST service and a full HTML5/Javascript client with angularjs in second part. You can do that in one maven project using https://github.com/eirslett/frontend-maven-plugin
I have a java application consisting of a static HTML page and JS. In the application I have REST-like API which is called by JS from static HTML. In front of the application is a front-end proxy server, say Nginx or Apache.
the front-end server is located on server S1 and servlet container is located on server S2.
I have a page http://example.com/mycontext/page.html which includes the JS file invoking REST API located at http://example.com/mycontext/api/someresource
The front-end passes all request matching http://example.com/mycontext/ to my application.
I want to introduce another web api in my application for internal use only, i.e. this new api should be invoked and visible only by other applications in my intranet (say from server S3), not from the internet.
I want this api to be HTTP-based, WS or REST-like, and to be managed by the same servlet container, say Tomcat, in which my app is deployed.
What options do I have?
My front-end passes all request matching http://example.com/mycontext/* to my application
The easiest answer in this case would be to change the front end not to pass http://example.com/mycontext/private/* through, and then have other servers access your internal API directly on http://server.internal.ip:8080/mycontext/private.