twogoods
twogoods

Reputation: 1916

how to change <host:port> to domain in swagger

enter image description here

in the picture swagger request use host and port,so browser console XMLHttpRequest cannot load http://115.159.22.159:9001/bp/api/v1/user/1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://twogoods.cc' is therefore not allowed access. how to solve it?

Upvotes: 4

Views: 9727

Answers (2)

Nick Grealy
Nick Grealy

Reputation: 25942

You can use the host(..) and protocols(..) methods, to override the default values.

e.g.

@Bean
public Docket customImplementation() {
    return new Docket(DocumentationType.SWAGGER_2)
        .protocols(Collections.singleton("https"))
        .host("twogoods.cc")
        .select()
        .build();
}

Upvotes: 1

twogoods
twogoods

Reputation: 1916

@Bean
public Docket categoryApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .host("twogoods.cc")
            .groupName("bookplatform-api")
            .apiInfo(apiInfo())
            .select()
            .paths(apiPaths())
            .build()
            .directModelSubstitute(java.sql.Timestamp.class, java.sql.Date.class)
            .enableUrlTemplating(false);
}

host() method!!!

Upvotes: 3

Related Questions