spring-cloud-netflix
spring-cloud-netflix copied to clipboard
Is it possible to override the basePath used in eureka templates?
Hi, it seems that the basePath used in eureka freemarker templates (like this one) can not be overridden and is hard coded to '/' in the EurekaController. Can you please tell me if my understanding is correct? Thank you for your help.
Can you describe why you want to change the basePath?
Sure, I have my eureka server hosted under http://myserver/somePath. Since the basePath is assumed to be '/' the template is trying to load static content from http://myserver/. For example, the template tries to load http://myserver/eureka/css/wro.css but it should load http://myserver/somePath/eureka/css/wro.css. I'm open to other suggestions on how to resolve this if I can do something other than changing the basePath (I have to host it under somePath though). Thank you for your help.
Try setting eureka.dashboard.path
I looked into that but let me expand on something. http://myserver/somePath is the route to the root of my eureka service. i.e. that path is created outside of the eureka service itself. If I set eureka.dashboard.path=somePath I would then need to access the dashboard from http://myserver/somePath/somePath. Hosting the root of my service under http://myserver/somePath is unfortunately a constraint.
It's not something we support at this time.
Understood, thank you for your responses.
Hi, I ran into a similar use case:
When the eureka server is behind a gateway (e.g., zuul reverse proxy), the zuul route prefix is stripped and is put into the x-forwarded-prefix
header.
So, it would be nice if the basePath was configurable or was picked up from the x-forwarded-prefix
header.
By use ingress-nginx in k8s, there're 2 annotations for rewrite in this case (but deprecated in 0.22.0): nginx.ingress.kubernetes.io/add-base-url nginx.ingress.kubernetes.io/base-url-scheme
The generated nginx conf is:
set_escape_uri $escaped_base_uri $baseuri;
subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="https://$http_host/xxxx/$escaped_base_uri">' ro;
I guess similar conf is required in other gateways, if eureka use static basePath.
Bumping this issue. same as Spring Boot Admin they handle the base path (almost) the same way as you do. Very troublesome when behind a Zuul Proxy for example.