Home > Net >  Setting up Angular with an external serverside Backend
Setting up Angular with an external serverside Backend

Time:10-02

I want to preface all of this by saying I'm a pretty new developer. If there's any clarification needed because my question is not preicse enough I'll gladly provide!

So as part of my current education we're doing something they call pop-up internship where you go to visit a company for a day or two and run through a couple different departments to get a feel for how different companies might tackle some of the daily tasks they encounter.

One company in particular had an app in development that really got me interested. They were building a web application for one of their customers based on the Angular framework from what I understand. The backend/serverside code was written Java. The interesting part is that they used some way to turn the expoted Java-WAR into a file they would include in the Angular project. It allowed them to use the methods, and probably more important the classes, defined in the Java-part of their project directly on the client-side. This seemed like a super interesting concept to me and I would really like to do something like that for an app of my own now.

I don't have any experience with Java, writing mostly little PHP and C# applications so far so I wondered - is a model like this possible to set up with Angular and PHP? If yes, where do I need to look in terms of guidance to set something like that up with my Angular project? What are some key things I need to know before tackling something like this? Is it even worth doing like that?

There's a lot floating in my head right now regarding this because this is kinda exciting to me, any and all help would be greatly appreciated

CodePudding user response:

Are you really sure that they used Java classes in Angular? Because Angular is definitely Javascript based, and Java !=Javascript.

While I can imagine that they wrote some kind of framework that translates some of their Java classes to JS classes (= generates the .js file content from the .java file content), that would never be done with source code in the compiled WAR-file (WAR-file = zipped, compiled Java .class files).

--

How I would combine Java Angular:

--a java project like this:

- src/main
  - /java
    - <java packages and classes>
  - /resources/webapp
    - web.xml (configuration of landing point, security, etc.)
    - /angular-generated (empty folder)

--an angular project, either completely outside the java project structure or somewhere like src/main/ui

--A (Java) build process that generates the WAR file, triggers the Angular (NodeJS) build process, and then copies the generated Angular HTML JS files to the /angular-generated folder inside the WAR-file.

(More intelligent build proccess: trigger the Angular build first, copy the files to src/main/resources/angular-generated, and THEN do the Java WAR building).

Great Tutorial example: https://medium.com/bb-tutorials-and-thoughts/how-to-develop-and-build-angular-app-with-java-backend-87fb603c6e17


How I would combine PHP Angular:

  • make sure that PHP only provides APIs instead of generate frontend HTML
  • starting point: index.html
  • separate Angular project, dev-configuration for localhost:php-port/url as backend, prod-configuration for /url as backend
  • Build process that builds the Angular files and then copies the html to index.html and the other files into the same folder.
  • Related