Setting base url for urls generated with Spring

We have a restful api running with spring that generates HATEOAS links. When I start the service locally they are generated fine, but on our server that hosts tomcat behind apache which proxies the application to / api / (locally it just starts at /) the urls are still generated as the application is launched at / ...

Is there a way to tell spring to use the base url when creating them?

+3


source to share


1 answer


I figured out my problem. Spring was not to blame. When building links, Spring uses X-Forwarded-Host, X-Forwarded-Ssl, etc., and since 4.1.3 it uses X-Forwarded-Prefix to properly build URLs that will be forwarded by the proxy. However, this latter is not automatically installed by apache when proxying, so setting mod_headers and adding it RequestHeader set X-Forwarded-Prefix "api"

to my LocationMatch directive allows everything.



+3


source







All Articles