From c00f2c172e267736d6013d71e7519d0ff3e2bd56 Mon Sep 17 00:00:00 2001 From: nonaninona <53222283+nonaninona@users.noreply.github.com> Date: Sat, 27 Jan 2024 18:45:02 +0900 Subject: [PATCH] =?UTF-8?q?Feat=20:=20Chat=20230=20CORS=20=ED=97=88?= =?UTF-8?q?=EC=9A=A9=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix : docker build args 누락 수정 * Feat : CORS 설정 FE의 로컬 작업을 위해 모든 origin에 대해 허용 설정 * Chore : cd 브랜치 설정 제거 * Feat : 웹소켓에서의 CORS도 허용 --- Dockerfile | 16 +++++++++++++++- .../java/com/kuit/chatdiary/WebConfig.java | 18 ++++++++++++++++++ .../websocket/ChatWebSocketConfig.java | 3 ++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/kuit/chatdiary/WebConfig.java diff --git a/Dockerfile b/Dockerfile index 22ea12d5..4ed8c75c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,18 @@ ARG JAR_PATH=/build/libs/*.jar COPY ${JAR_PATH} /home/server.jar ENTRYPOINT ["java","-jar","/home/server.jar"] ARG OPEN_AI_KEY -ENV OPEN_AI_KEY=${OPEN_AI_KEY} \ No newline at end of file +ENV OPEN_AI_KEY=${OPEN_AI_KEY} +ARG DEV_DB_HOST +ENV DEV_DB_HOST=${DEV_DB_HOST} +ARG DEV_DB_PASSWORD +ENV DEV_DB_PASSWORD=${DEV_DB_PASSWORD} +ARG DEV_DB_USER +ENV DEV_DB_USER=${DEV_DB_USER} +ARG PROD_DB_HOST +ENV PROD_DB_HOST=${PROD_DB_HOST} +ARG PROD_DB_PASSWORD +ENV PROD_DB_PASSWORD=${PROD_DB_PASSWORD} +ARG PROD_DB_USER +ENV PROD_DB_USER=${PROD_DB_USER} +ARG ACTIVE_PROFILE +ENV ACTIVE_PROFILE=${ACTIVE_PROFILE} \ No newline at end of file diff --git a/src/main/java/com/kuit/chatdiary/WebConfig.java b/src/main/java/com/kuit/chatdiary/WebConfig.java new file mode 100644 index 00000000..70e515ca --- /dev/null +++ b/src/main/java/com/kuit/chatdiary/WebConfig.java @@ -0,0 +1,18 @@ +package com.kuit.chatdiary; + +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + public static final String ALLOWED_METHOD_NAMES = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,PATCH"; + + @Override + public void addCorsMappings(final CorsRegistry registry) { + registry.addMapping("/**") + .allowedMethods(ALLOWED_METHOD_NAMES.split(",")) + .exposedHeaders(HttpHeaders.LOCATION); + } +} \ No newline at end of file diff --git a/src/main/java/com/kuit/chatdiary/websocket/ChatWebSocketConfig.java b/src/main/java/com/kuit/chatdiary/websocket/ChatWebSocketConfig.java index ab66b3fc..69692ed7 100644 --- a/src/main/java/com/kuit/chatdiary/websocket/ChatWebSocketConfig.java +++ b/src/main/java/com/kuit/chatdiary/websocket/ChatWebSocketConfig.java @@ -15,6 +15,7 @@ public class ChatWebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(chatWebSocketHandler, "/chatwebsocket"); + registry.addHandler(chatWebSocketHandler, "/chatwebsocket") + .setAllowedOrigins("*"); } }