Skip to content

Commit

Permalink
feature: 개발용 / 배포용 개발 환경 분리
Browse files Browse the repository at this point in the history
- application.yaml에서 local / prod로 구분지어서 사용 가능
- SecurityConfig에서 개발 환경에 맞게 url 변경
  • Loading branch information
ss0ngcode committed Aug 29, 2024
1 parent fd0dabb commit 7c5cc79
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -39,6 +40,9 @@ public class SecurityConfig {
private static final Logger log = LoggerFactory.getLogger(SecurityConfig.class);
private final CustomOAuth2Service customOAuth2Service;

@Value("${base.url}")
private String baseUrl;

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
Expand Down Expand Up @@ -71,7 +75,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
)
.logout(logout -> logout
.logoutUrl("/api/auth/logout")
.logoutSuccessUrl("http://localhost:3000")
.logoutSuccessUrl(baseUrl)
.deleteCookies("JSESSIONID")
)
.exceptionHandling(exceptionHandling -> exceptionHandling
Expand All @@ -90,10 +94,10 @@ public AuthenticationSuccessHandler successHandler() {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException {
if (isUnregisteredUser(authentication)) {
response.sendRedirect("http://localhost:3000/register");
response.sendRedirect(baseUrl + "/register");
return;
}
response.sendRedirect("http://localhost:3000/login/ok");
response.sendRedirect(baseUrl + "/login/ok");
}

private boolean isUnregisteredUser(Authentication authentication) {
Expand All @@ -114,7 +118,7 @@ public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();

config.setAllowCredentials(true);
config.setAllowedOrigins(List.of("http://localhost:3000"));
config.setAllowedOrigins(List.of(baseUrl));
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
config.setAllowedHeaders(List.of("*"));
config.setExposedHeaders(List.of("*"));
Expand Down
124 changes: 87 additions & 37 deletions server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,19 @@
spring:
application:
name: talkka-server
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${MYSQL_URL}
username: ${MYSQL_USERNAME}
password: ${MYSQL_PASSWORD}
sql:
init:
mode: never # schema.sql 실행시 always 키고 실행하시면 됩니다.
jpa:
hibernate:
ddl-auto: validate
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect
show-sql: true
security:
oauth2:
client:
registration:
naver:
client-id: ${NAVER_CLIENT_ID}
client-secret: ${NAVER_CLINET_SECRET}
redirect_uri: http://localhost:8080/api/auth/login/naver/code
client-name: Naver
authorization-grant-type: authorization_code
scope:
- name
- email
provider:
naver:
authorization-uri: https://nid.naver.com/oauth2.0/authorize
token-uri: https://nid.naver.com/oauth2.0/token
user-info-uri: https://openapi.naver.com/v1/nid/me
user-name-attribute: response
profiles:
active: prod # 개발 환경에 따라 변경할 것 (local | prod)
thymeleaf:
prefix: classpath:/templates/
suffix: .html


openapi:
public:
bus:
service-key:
keys:
- ${SERVICE_KEY_1}


bus:
location:
collect:
Expand Down Expand Up @@ -82,4 +47,89 @@ springdoc:
api-docs:
path: /api-docs
default-consumes-media-type: application/json
---
spring:
config:
activate:
on-profile: local
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${MYSQL_URL}
username: ${MYSQL_USERNAME}
password: ${MYSQL_PASSWORD}
sql:
init:
mode: never # schema.sql 실행시 always 키고 실행하시면 됩니다.
jpa:
hibernate:
ddl-auto: validate
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect
show-sql: true
security:
oauth2:
client:
registration:
naver:
client-id: ${NAVER_CLIENT_ID}
client-secret: ${NAVER_CLIENT_SECRET}
redirect_uri: http://localhost:8080/api/auth/login/naver/code
client-name: Naver
authorization-grant-type: authorization_code
scope:
- name
- email
provider:
naver:
authorization-uri: https://nid.naver.com/oauth2.0/authorize
token-uri: https://nid.naver.com/oauth2.0/token
user-info-uri: https://openapi.naver.com/v1/nid/me
user-name-attribute: response

base:
url: http://localhost:3000
---
spring:
config:
activate:
on-profile: prod
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${MYSQL_URL}
username: ${MYSQL_USERNAME}
password: ${MYSQL_PASSWORD}
sql:
init:
mode: never
jpa:
hibernate:
ddl-auto: validate
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect
show-sql: false
security:
oauth2:
client:
registration:
naver:
client-id: ${NAVER_CLIENT_ID}
client-secret: ${NAVER_CLIENT_SECRET}
redirect_uri: https://talkka-bus/api/auth/login/naver/code
client-name: Naver
authorization-grant-type: authorization_code
scope:
- name
- email
provider:
naver:
authorization-uri: https://nid.naver.com/oauth2.0/authorize
token-uri: https://nid.naver.com/oauth2.0/token
user-info-uri: https://openapi.naver.com/v1/nid/me
user-name-attribute: response

base:
url: https://talkka-bus:3000 # 추후 프론트에 맞게 수정 필요

0 comments on commit 7c5cc79

Please sign in to comment.