-
-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable base context to angular and spring app #357
base: 1.7.x
Are you sure you want to change the base?
Add configurable base context to angular and spring app #357
Conversation
3511af7
to
4e3abe8
Compare
Could you explain the motivation with this PR? We had previous discussion (like for example in #320) about that and ended-up with it not being a harde requirement because you could mostly always find a gateway configuration to handle that. Is there some specific issues we wouldn't be able to handle ? PR seems to involve a large set of resources... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some questions about required changes ...
Also it would be nice removing unnecessary formatting changes (like introduced spaces or new lines) to ease-up a complete review later.
keycloak.cors=true | ||
keycloak.cors-max-age=3600 | ||
keycloak.cors-allowed-methods=POST, PUT, DELETE, GET, OPTIONS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why this is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that all APIs that are secured by Keycloak could no longer be called locally by the Angular app in development mode. Background is (see comment on proxy.conf), the angular app is accessible at http://localhost:4200 and the spring boot app is accessible at http://localhost:8080. So we would have a CORS issue. Link to the Keycloak issue.
"browserTarget": "microcks-ui:build", | ||
"proxyConfig": "proxy.conf.json" | ||
}, | ||
"browserTarget": "microcks-ui:build" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proxy.conf.json
is necessary while in development mode. I use ng serve
to serve the frontend with hot-reload and backend is ran with mvn spring-boot:run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually i do the same with ng serve
and mvn spring-boot:run
but I changed that the Angular services do not use the hardcoded /api/
path instead the (https://github.com/fhopfensperger/microcks/blob/4e3abe87d93030588c2ebc6bd50f115db4a5282c/webapp/src/main/webapp/src/app/services/importers.service.ts#L27) services load the actual address + path from the environment
. Because of this I have configured the environment.ts
file and removed the not longer needed proxy.conf.json
:
export const environment = {
production: false,
apiUrl: 'http://localhost:8080/',
baseContext: '/'
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But something just comes to my mind, we could define in the environment only the /
as apiUrl
and keep the proxy.conf. Maybe we can fix the CORS issue as well. If you want I can try it out.
webapp/src/main/webapp/src/main.ts
Outdated
console.log = () => { }; | ||
console.warn = () => { }; | ||
console.error = () => { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea but I would have let console.error
though.. to be sure to grab critical messages.
@@ -4,7 +4,7 @@ For development purposes, frontend GUI and backend APIs have been separated and | |||
* Frontend is an Angular 6 application served by `ng serve` with livereload enabled, | |||
* Backend is a Spring Boot application served by Boot internal server | |||
|
|||
We also need a Keycloak server running on port `8180`. | |||
We also need a Keycloak server running on port `8180`. You can run the Keycloak server as a container from docker-compose, just adjust the exposed port to `8180`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -25,7 +25,7 @@ $ ./standalone.sh -Djboss.socket.binding.port-offset=100 | |||
In a terminal, start frontend GUI server using NG : | |||
|
|||
``` | |||
$ cd src/main/webapp | |||
$ cd webapp/src/main/webapp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:/deployments/assets/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't understand why this should be now necessary ... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default (baeldung) Spring doesn't serve static files from /deployments/asssets/*
.
I use this path to mount a ConfigMap
(which holds the Angular environment
configuration) as a volume to the running pod. Which then allow the Angular App to get the Backend URL and other configuration properties.
https://github.com/fhopfensperger/microcks/blob/4e3abe87d93030588c2ebc6bd50f115db4a5282c/install/kubernetes/microcks/templates/configmap.yaml#L390
https://github.com/fhopfensperger/microcks/blob/4e3abe87d93030588c2ebc6bd50f115db4a5282c/webapp/src/main/webapp/src/environments/environment-loader.ts#L8
https://github.com/fhopfensperger/microcks/blob/4e3abe87d93030588c2ebc6bd50f115db4a5282c/install/kubernetes/microcks/templates/deployment.yaml#L114
Hi @lbroudoux Main reason for the PR was the fact that I have a Kubernetes cluster that has a single external DNS. The DNS entry is routed to the Istio ingress gateway, which then decides which service to route the request to based on sub-path. So unfortunately I cannot implement what has been described in #320, because I don't "have" an "typical" ingress controller. Also when I started the PR, there was no solution for the issue. 😅 Right now I have the implementation running in an AKS cluster and am in the process of testing the same locally on my minikube and CRC with and without sub path.
|
Would love to fix the formatting issues, what type of formatter do you use for the Typescript and Java code? |
14adaf7
to
1c861cb
Compare
Short update from my side. The current implementation (Rest Mocking functionality) has been successfully tested on the following platforms and ingress types:
I have not tested the |
Because: - Allows ingress subpath configuration - Avoids separate external dns names for services Signed-off-by: Florian Hopfensperger <florian.hopfensperger@de.ibm.com>
1c861cb
to
39e0a7c
Compare
@fhopfensperger @lbroudoux what is the reason for the inactivity on this PR? |
Hi, |
I just updated to branch |
Hi, Thanks for your response. I would definitely find this useful. We are looking to deploy in Azure Kubernetes Service using application gateway ingress controller and the only option we have is to run it at a different context path than root. Keycloak now supports this using the --hostname-url and --admin-hostname-url options in the start command or similarly by setting environment variables. |
Great! As I think I've been too long to answer to keep @fhopfensperger in the loop - sorry for that! - I'd need some help for review, testing and validation. @keiranbatten-nzta Would you be ready to help on that tasks if I push this one up? |
This PR allows to configure a subcontext (sub http path) for the Angular and Spring boot app and Keycloak. For example, the services then listen to the following urls:
https://example.com/mock-server/auth/
&https://example.com/mock-server/microcks/
Work is still in progress, but I already have a working deployment up and running on my Azure Kubernetes cluster with Istio.
Signed-off-by: Florian Hopfensperger florian.hopfensperger@de.ibm.com