From e9ef4f5c36fe3caff139d4751f4984ab837eab9d Mon Sep 17 00:00:00 2001 From: Khanh Du Date: Thu, 10 Oct 2024 14:49:54 +0700 Subject: [PATCH] config ngxin run good with keycloak --- docker-compose.yml | 2 -- nginx/templates/default.conf.template | 25 ++++++------------- pom.xml | 4 +++ product/src/main/resources/application.yml | 13 +++++++--- .../fjb/sellbff/config/SecurityConfig.java | 3 ++- sell-bff/src/main/resources/application.yaml | 9 ++++++- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b92e589..1b7c476 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,8 +29,6 @@ services: - ./identity/themes/matcha/theme:/opt/keycloak/themes networks: - matcha-network - ports: - - "8080:80" postgres: image: debezium/postgres:15-alpine diff --git a/nginx/templates/default.conf.template b/nginx/templates/default.conf.template index f788ca4..68e435b 100644 --- a/nginx/templates/default.conf.template +++ b/nginx/templates/default.conf.template @@ -1,29 +1,18 @@ server { - server_name 127.0.0.11; - - # Docker DNS - resolver 127.0.0.11; - - location /swagger-ui/ { - proxy_pass http://swagger-ui:8090; - } - location /product/ { - proxy_pass http://product; - } } -server { - server_name sell; - location / { - proxy_pass http://sell; - } -} +#server { +# server_name sell; +# location / { +# proxy_pass http://localhost:8181; +# } +#} server { server_name identity; large_client_header_buffers 8 32k; location / { - proxy_pass http://identity; + proxy_pass http://keycloak:80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/pom.xml b/pom.xml index 7c9ae54..e6dc77b 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,10 @@ org.springdoc springdoc-openapi-starter-webmvc-ui + + me.paulschwarz + spring-dotenv + diff --git a/product/src/main/resources/application.yml b/product/src/main/resources/application.yml index 08cb261..26e4bec 100644 --- a/product/src/main/resources/application.yml +++ b/product/src/main/resources/application.yml @@ -8,13 +8,18 @@ spring: driver-class-name: org.postgresql.Driver jpa: - properties: - hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect - format_sql: true hibernate: ddl-auto: update show-sql: true + properties: + hibernate: + format_sql: false + database: postgresql + database-platform: org.hibernate.dialect.PostgreSQLDialect + open-in-view: false + + dotenv: + file: ../.env server: port: 8081 diff --git a/sell-bff/src/main/java/com/fjb/sellbff/config/SecurityConfig.java b/sell-bff/src/main/java/com/fjb/sellbff/config/SecurityConfig.java index 15bf455..4a9bd49 100644 --- a/sell-bff/src/main/java/com/fjb/sellbff/config/SecurityConfig.java +++ b/sell-bff/src/main/java/com/fjb/sellbff/config/SecurityConfig.java @@ -37,7 +37,8 @@ public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) return http .authorizeExchange(auth -> auth .pathMatchers("/health").permitAll() - .anyExchange().hasAnyRole("ADMIN")) +// .anyExchange().hasAnyRole("ADMIN")) + .anyExchange().permitAll()) .oauth2Login(Customizer.withDefaults()) .httpBasic(ServerHttpSecurity.HttpBasicSpec::disable) .formLogin(ServerHttpSecurity.FormLoginSpec::disable) diff --git a/sell-bff/src/main/resources/application.yaml b/sell-bff/src/main/resources/application.yaml index ed4d059..c50cb37 100644 --- a/sell-bff/src/main/resources/application.yaml +++ b/sell-bff/src/main/resources/application.yaml @@ -44,10 +44,17 @@ spring: gateway: routes: # Changes for your local development should not be committed - - id: api_product_local + - id: product uri: http://localhost:8081 predicates: - Path=/api/product/** filters: - RewritePath=/api/(?.*), /$\{segment} - TokenRelay= + - id: localhost + uri: http://localhost:80 + predicates: + - Path=/api/** + filters: + - RewritePath=/api/(?.*), /$\{segment} + - TokenRelay=