diff --git a/song-server/src/main/java/bio/overture/song/server/config/SwaggerConfig.java b/song-server/src/main/java/bio/overture/song/server/config/SwaggerConfig.java index 60dd1ded9..f41d284b4 100644 --- a/song-server/src/main/java/bio/overture/song/server/config/SwaggerConfig.java +++ b/song-server/src/main/java/bio/overture/song/server/config/SwaggerConfig.java @@ -27,6 +27,7 @@ import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.paths.RelativePathProvider; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger.web.UiConfiguration; import springfox.documentation.swagger2.annotations.EnableSwagger2; @@ -42,15 +43,30 @@ public class SwaggerConfig { @Getter private String alternateSwaggerUrl; + // default is empty + @Value("${swagger.host:}") + private String swaggerHost; + + // default is empty + @Value("${swagger.basePath:}") + private String basePath; + @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(basePackage("bio.overture.song.server.controller")) - .paths(any()) .build() - .pathMapping("/"); + .host(swaggerHost) + .pathProvider( + new RelativePathProvider(null) { + @Override + public String getApplicationBasePath() { + return basePath; + } + } + ); } @Bean diff --git a/song-server/src/main/resources/application.yml b/song-server/src/main/resources/application.yml index c8c4fd82b..1b079eb60 100644 --- a/song-server/src/main/resources/application.yml +++ b/song-server/src/main/resources/application.yml @@ -80,6 +80,11 @@ management: swagger: alternateUrl: "/api-docs" + # host and base url are needed if you run song behind a reverse proxy + # and rewrite the url eg: http://mydomain.com/song/swagger-ui.html + # in this case host = mydomain.com, baseUrl = /song + host: "" + basePath: "" security.basic.enabled: false