Skip to content

Commit

Permalink
fix(cors): cors 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhboy committed Feb 2, 2024
1 parent c434a3a commit edbd77c
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.sickgyun.server.common.config;

import static org.springframework.http.HttpHeaders.*;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand All @@ -15,11 +18,33 @@
@Configuration
@RequiredArgsConstructor
public class InterceptorConfig implements WebMvcConfigurer {

private static final String ALLOW_ALL_PATH = "/**";
private static final String ALLOWED_METHODS = "*";
private static final String MAIN_SERVER_DOMAIN = "https://zipgo.pet";
private static final String DEV_SERVER_DOMAIN = "https://dev.zipgo.pet";
private static final String FRONTEND_LOCALHOST = "http://localhost:3000";
private static final String HTTPS_FRONTEND_LOCALHOST = "https://localhost:3000";

private final JwtParser jwtParser;
private final AuthUpdater authUpdater;
private final AuthReader authReader;
private final UserReader userReader;

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(ALLOW_ALL_PATH)
.allowedMethods(ALLOWED_METHODS)
.allowedOrigins(
MAIN_SERVER_DOMAIN,
DEV_SERVER_DOMAIN,
FRONTEND_LOCALHOST,
HTTPS_FRONTEND_LOCALHOST
)
.allowCredentials(true)
.exposedHeaders(LOCATION, SET_COOKIE);
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new AuthInterceptor(jwtParser, authUpdater, authReader, userReader));
Expand Down

0 comments on commit edbd77c

Please sign in to comment.