Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a base url for urls generated by Spring

We've got a restful api running using spring which generates HATEOAS links. When I run the service locally, they are generated fine, but on our server, which hosts tomcat behind apache which proxies the app to /api/ (locally it's just run on /), the urls are still generated like the app is run on /.

Is there any way to tell spring to use a base url when generating these?

like image 640
thepandaatemyface Avatar asked Apr 22 '15 08:04

thepandaatemyface


People also ask

What is base URL in URL?

The URL found in the address bar of the front page of a website is its base URL. In other words, the common prefix found while navigating inside a given website is known as the base URL. One can select a base URL from the list of those available with help of the URL general properties page.


1 Answers

I've figured out my problem. Spring wasn't at fault. When building links, spring uses the X-Forwarded-Host, X-Forwarded-Ssl, etc. and, since 4.1.3, X-Forwarded-Prefix to correctly build urls that will be forwarded by a proxy. This last one however, is not automatically set by apache when proxying, so installing mod_headers and adding RequestHeader set X-Forwarded-Prefix "api"to my LocationMatch directive solved everything.

like image 128
thepandaatemyface Avatar answered Sep 24 '22 16:09

thepandaatemyface