demo-decoupled docker-compose
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
services:
|
||||
backend:
|
||||
build: .
|
||||
container_name: decoupled_backend
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
- SPRING_DATASOURCE_URL=jdbc:postgresql://jambo-postgres:5432/springangulardb
|
||||
- SPRING_DATASOURCE_USERNAME=springangular_user
|
||||
- SPRING_DATASOURCE_PASSWORD=postgrespw
|
||||
- SPRING_DATASOURCE_DRIVER-CLASS-NAME=org.postgresql.Driver
|
||||
networks:
|
||||
- jambotron-net
|
||||
|
||||
frontend:
|
||||
build: ./spring-angular-ui
|
||||
container_name: decoupled_frontend
|
||||
ports:
|
||||
- "8081:80"
|
||||
networks:
|
||||
- jambotron-net
|
||||
|
||||
networks:
|
||||
jambotron-net:
|
||||
external: true
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
FROM eclipse-temurin:26-jdk-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN chmod +x gradlew
|
||||
RUN ./gradlew bootJar -x test --no-daemon
|
||||
|
||||
FROM eclipse-temurin:26-jre-alpine
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/build/libs/*.jar app.jar
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||
@@ -0,0 +1,13 @@
|
||||
# Этап сборки Angular
|
||||
FROM node:20-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install --legacy-peer-deps
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Этап раздачи через Nginx
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /app/static/browser /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -101,7 +101,9 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http.csrf(csrf -> csrf.disable())
|
||||
http
|
||||
.cors(cors -> cors.configurationSource(corsConfigurationSource())) // Включаем CORS
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth ->
|
||||
@@ -126,4 +128,19 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
// Добавляем метод конфигурации CORS источников и разрешенных методов
|
||||
@Bean
|
||||
public org.springframework.web.cors.CorsConfigurationSource corsConfigurationSource() {
|
||||
org.springframework.web.cors.CorsConfiguration configuration = new org.springframework.web.cors.CorsConfiguration();
|
||||
// Укажите порты, с которых разрешено ходить (например, ваш Angular на 8081 и дефолтный 4200)
|
||||
configuration.setAllowedOrigins(java.util.List.of("http://localhost:8081", "http://localhost:4200", "http://localhost"));
|
||||
configuration.setAllowedMethods(java.util.List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
|
||||
configuration.setAllowedHeaders(java.util.List.of("*"));
|
||||
configuration.setAllowCredentials(true);
|
||||
|
||||
org.springframework.web.cors.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
spring:
|
||||
application:
|
||||
name: demo-deoupled
|
||||
name: demo-decoupled
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/springangulardb
|
||||
url: jdbc:postgresql://jambo-postgres:5432/springangulardb
|
||||
username: springangular_user
|
||||
password: postgrespw
|
||||
flyway:
|
||||
enabled: true
|
||||
baseline-on-migrate: true
|
||||
url: jdbc:postgresql://localhost:5432/springangulardb?options=-c%20timezone=UTC
|
||||
url: jdbc:postgresql://jambo-postgres:5432/springangulardb?options=-c%20timezone=UTC
|
||||
user: springangular_user
|
||||
password: postgrespw
|
||||
jpa:
|
||||
|
||||
Reference in New Issue
Block a user