Skip to content

Commit

Permalink
Merge pull request #10 from Kusitms-28th-Meet-Up-B/feature/#1/mainAPI
Browse files Browse the repository at this point in the history
feat : Swagger 추가 및 Cors 문제
  • Loading branch information
MyunghyunNero authored Oct 28, 2023
2 parents e93687b + 0bb3f6a commit 98c44e6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/kusitms/gallae/config/OpenAPIConfig.java
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SpringSecurityConfig {
public SecurityFilterChain SecurityFilterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeHttpRequests()
.requestMatchers("/v3/**", "/swagger-ui/**").permitAll()
.anyRequest().permitAll().and()
.exceptionHandling()
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint)
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/kusitms/gallae/config/WebMvcConfig.java
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");;
}
}

0 comments on commit 98c44e6

Please sign in to comment.