add cookie
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package ru.soune.no_copy.configuration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
|
||||
config.setAllowedOrigins(Arrays.asList(
|
||||
"http://92.242.61.23:2998",
|
||||
"http://localhost:3000",
|
||||
"http://localhost:2998"
|
||||
));
|
||||
|
||||
config.setAllowedMethods(Arrays.asList("*"));
|
||||
config.setAllowedHeaders(Arrays.asList("*"));
|
||||
config.setExposedHeaders(Arrays.asList("Set-Cookie", "Authorization"));
|
||||
config.setAllowCredentials(true); // ВАЖНО!
|
||||
config.setMaxAge(3600L);
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,27 @@
|
||||
spring:
|
||||
session:
|
||||
timeout: 7d
|
||||
cookie:
|
||||
name: SESSION_ID
|
||||
http-only: true
|
||||
secure: false
|
||||
same-site: none
|
||||
max-age: 604800
|
||||
|
||||
cors:
|
||||
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://92.242.61.23:2998,http://localhost:3000}
|
||||
allowed-methods: GET,POST,PUT,DELETE,OPTIONS,PATCH,HEAD
|
||||
allowed-headers: "*"
|
||||
exposed-headers: Set-Cookie,Authorization,Content-Type
|
||||
allow-credentials: true # ВАЖНО для кук!
|
||||
max-age: 3600
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.springframework.web.cors: DEBUG
|
||||
org.springframework.security: DEBUG
|
||||
org.springframework.web: DEBUG
|
||||
|
||||
datasource:
|
||||
url: jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
|
||||
username: ${POSTGRES_USER}
|
||||
@@ -9,10 +32,28 @@ spring:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
|
||||
server:
|
||||
port: ${SERVER_PORT:8080}
|
||||
servlet:
|
||||
session:
|
||||
cookie:
|
||||
same-site: none
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
enabled: true
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
org.springframework.web.cors: TRACE # Более детальные логи
|
||||
org.springframework.session: DEBUG
|
||||
pattern:
|
||||
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file:
|
||||
name: ./logs/app.log
|
||||
max-size: 10MB
|
||||
max-history: 30
|
||||
Reference in New Issue
Block a user