diff --git a/src/main/java/uk/gov/beis/els/api/openapi/OpenApiService.java b/src/main/java/uk/gov/beis/els/api/openapi/OpenApiService.java index 337bfccb..47236216 100644 --- a/src/main/java/uk/gov/beis/els/api/openapi/OpenApiService.java +++ b/src/main/java/uk/gov/beis/els/api/openapi/OpenApiService.java @@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import org.springframework.web.util.UriComponentsBuilder; import uk.gov.beis.els.api.common.ApiDocumentationController; import uk.gov.beis.els.api.common.TagNotFoundException; import uk.gov.beis.els.api.model.OperationWithSchema; @@ -66,9 +67,15 @@ public String getApiSpecUrl(HttpServletRequest request) { } public String getBaseUrl(HttpServletRequest request) { - return ServletUriComponentsBuilder.fromRequestUri(request) - .replacePath(null) - .build() + UriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(request) + .replacePath(null); + + String xForwardedProto = request.getHeader("X-Forwarded-Proto"); + if (xForwardedProto != null) { + builder.scheme(xForwardedProto); + } + + return builder.build() .toUriString(); }