From 7765c721cadc204e00ba89a7b6da3c4fb49c8928 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 11 Dec 2014 16:52:17 -0700 Subject: [PATCH] basePath should always be /contextPath/servletPath/ (the last slash being the location of the eureka dashboard) fixes gh-101 --- .../netflix/eureka/server/EurekaController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java index 220b9b87..8fa5921b 100644 --- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java +++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java @@ -11,6 +11,8 @@ import com.netflix.eureka.cluster.PeerEurekaNode; import com.netflix.eureka.resources.StatusResource; import com.netflix.eureka.util.StatusInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -26,6 +28,9 @@ import java.util.*; @Controller public class EurekaController { + @Autowired + ServerProperties serverProperties; + @RequestMapping(value = "/", method = RequestMethod.GET) public String status(HttpServletRequest request, Map model) { populateBase(request, model); @@ -70,9 +75,10 @@ public class EurekaController { } protected void populateBase(HttpServletRequest request, Map model) { - String servletPath = request.getServletPath(); - String path = request.getContextPath() + (servletPath==null ? "" : servletPath); - String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path; + String contextPath = serverProperties.getContextPath(); + String path = (contextPath == null) ? "" : contextPath + serverProperties.getServletPath(); + path = path.replace("//", "/"); + String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path; if (!basePath.endsWith("/")) { basePath += "/";