2

I have a Spring Boot application with Spring Data Rest which I'm deploying via jar file with embedded Tomcat. The application runs on port 8080 but in front of Tomcat there's an httpd which passes the request through. Now the application comes with HATEOAS links, which I'm using in my JS-Client. The response looks something like this:

{
  "property" : "value"
  "_links" : {
    "self" : {
      "href" : "http://my.server:8080/resource/1"
    }
  }
}

My problem is that since I access the application via my.server, the application responds with an href to my.server:8080, which isn't accessible from the outside. How can I change the href hostname to my.server (without the port) without letting tomcat run under port 80? I tried subclassing RepositoryRestMvcConfiguration and setting the baseURI, but that does not work, since I get a 404 then.

osigge
  • 218
  • 4
  • 13
  • I suspect that this is essentially a dupe of http://stackoverflow.com/questions/24179807/is-there-a-means-to-set-the-host-port-for-the-spring-hateoas-controllerlinkbu – Steve Sep 23 '14 at 11:03
  • Also worth noting that there was a bug impacting things previously (https://jira.spring.io/browse/SPR-11872). Not sure whether it has been resolved in newer versions of spring-hateoas. – Steve Sep 23 '14 at 11:04

1 Answers1

1

If you can configure your httpd to not alter the HOST header you'll get what you're after as the default link builder uses the HOST header to construct URLs.

Alternatively you can have your httpd append an X-Forwarded-Host header, which overrides URL construction using the HOST header.

Chris DaMour
  • 3,650
  • 28
  • 37