Skip to content

Commit

Permalink
Merge pull request #712 from overture-stack/song/fix-swagger
Browse files Browse the repository at this point in the history
make swagger ui run behind reverse proxy
  • Loading branch information
blabadi authored Mar 5, 2021
2 parents 8d90246 + c62f29b commit 40ab4d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions song-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 40ab4d5

Please sign in to comment.