Skip to content

Commit

Permalink
Merge pull request #28 from CSID-DGU/develop
Browse files Browse the repository at this point in the history
Fix: Redis, CORS
  • Loading branch information
saokiritoni authored Nov 9, 2024
2 parents 684f9da + e17f03c commit 1f5d8f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions src/main/java/dongguk/osori/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
package dongguk.osori.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@Configuration
@EnableRedisHttpSession
@EnableRedisRepositories
public class RedisConfig {

@Value("${spring.redis.host}")
private String redisHost;

@Value("${spring.redis.port}")
private int redisPort;

@Value("${spring.redis.password}")
private String redisPassword;

@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory("localhost", 6379);
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(redisHost);
redisStandaloneConfiguration.setPort(redisPort);
redisStandaloneConfiguration.setPassword(redisPassword);
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer()); // Key๋ฅผ String์œผ๋กœ ์ง๋ ฌํ™”
template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); // Value๋ฅผ JSON์œผ๋กœ ์ง๋ ฌํ™”
return template;
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory());

return redisTemplate;
}
}
2 changes: 1 addition & 1 deletion src/main/java/dongguk/osori/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public PasswordEncoder passwordEncoder() {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(List.of("http://localhost:3000/**"));
configuration.setAllowedOrigins(List.of("http://localhost:3000")); // ์ •ํ™•ํ•œ ์˜ค๋ฆฌ์ง„ ์„ค์ •
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // ํ—ˆ์šฉํ•  HTTP ๋ฉ”์„œ๋“œ
configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type")); // ํ—ˆ์šฉํ•  HTTP ํ—ค๋”
configuration.setAllowCredentials(true); // ์ž๊ฒฉ ์ฆ๋ช… ํ—ˆ์šฉ
Expand Down

0 comments on commit 1f5d8f4

Please sign in to comment.