spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
913 stars 559 forks source link

HAL Browser go to entry point link wrong with a non-default context-path [DATAREST-971] #1341

Open spring-projects-issues opened 7 years ago

spring-projects-issues commented 7 years ago

Andrea Bollini opened DATAREST-971 and commented

I'm building a Spring Data REST application deployed on an external tomcat with a non-ROOT context-path. All works fine in the initial redirect to the HAL browser and subsequent links exploring the API excerpt for the top navigation link "Go to Entry point" that force the HAL browser to look for the REST API at #/

This should be related to https://github.com/mikekelly/hal-browser/issues/21

the solution should be to replace the entryPoint configured here https://github.com/mikekelly/hal-browser/blob/master/browser.html#L252 with the actual application contextPath


Affects: 2.5.6 (Hopper SR6)

2 votes, 5 watchers

spring-projects-issues commented 7 years ago

Oliver Drotbohm commented

Care to provide a sample project that reproduces the issue? Actually, we explicitly populate the entry point using the fragment identifier in the URI

spring-projects-issues commented 7 years ago

Andrea Bollini commented

Hi Oliver, thanks to look to this. Here a sample project https://github.com/abollini/hal-spring-data-rest-test

just checkout as test and run from eclipse as a webapplication in tomcat accessing http://localhost:8080/test/api you are redirected to http://localhost:8080/test/api/browser/index.html#/test/api and you will see the HAL browser working properly but if you click on the go to Entry point you are redirected to http://localhost:8080/test/api/browser/index.html#/

if you check the fix-index.html file in the root you see that the link is fixed initializing the HAL browser with the API location https://github.com/mikekelly/hal-browser/blob/master/browser.html#L252

spring-projects-issues commented 7 years ago

Jeroen Reijn commented

I have the same issue, but when using a custom basePath. In my project I use spring.data.rest.basePath=/api/v1

When I click the Entry point link the browser redirects to '/' which is incorrect in my case.

I've noticed that spring-boot-actuator replaces the entryPoint value by preprocessing the index.html/browser.html resource before serving it out to the client. See

https://github.com/spring-projects/spring-boot/blob/1.5.x/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpoint.java#replaceInitialLink