-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat : Swagger 추가 및 Cors 문제
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kusitms.gallae.config; | ||
|
||
|
||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.servers.Server; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class OpenAPIConfig { | ||
|
||
private final String devUrl; | ||
private final String prodUrl; | ||
|
||
public OpenAPIConfig( | ||
@Value("${votogether.openapi.dev-url}") final String devUrl, | ||
@Value("${votogether.openapi.prod-url}") final String prodUrl | ||
) { | ||
this.devUrl = devUrl; | ||
this.prodUrl = prodUrl; | ||
} | ||
|
||
@Bean | ||
public OpenAPI openAPI() { | ||
final Server devServer = new Server(); | ||
devServer.setUrl(devUrl); | ||
devServer.description("개발 환경 서버 URL"); | ||
|
||
final Server prodServer = new Server(); | ||
prodServer.setUrl(prodUrl); | ||
prodServer.description("운영 환경 서버 URL"); | ||
|
||
final Info info = new Info() | ||
.title("VoTogether API") | ||
.version("v1.0.0") | ||
.description("보투게더 API"); | ||
|
||
return new OpenAPI() | ||
.info(info) | ||
.servers(List.of(devServer, prodServer)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kusitms.gallae.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
public void addCorsMappings(CorsRegistry registry){ | ||
registry.addMapping("/**") | ||
.allowedOrigins("http://localhost:3000") | ||
.allowedMethods("OPTIONS", "GET", "POST", "PUT", "DELETE") | ||
.allowedOrigins("http://localhost:8000") | ||
.allowedMethods("OPTIONS", "GET", "POST", "PUT", "DELETE");; | ||
} | ||
} |