From 8d81afad3266cb75904591bb46d57e40debb9519 Mon Sep 17 00:00:00 2001 From: Artur Havliukovskyi Date: Mon, 20 Oct 2025 21:53:01 +0200 Subject: [PATCH] Configure proper proxy header pass to OpenAPI --- .github/workflows/on-release-tag.yml | 5 ++++- .../coursehub/CourseHubApplication.java | 1 - .../SwaggerBehindReverseProxyConfig.java | 21 ------------------- .../src/main/resources/application.properties | 6 ++---- deployment/README.md | 2 +- deployment/docker-compose.yaml | 11 +++++----- deployment/nginx.conf | 1 + 7 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 backend/src/main/java/net/hackyourfuture/coursehub/SwaggerBehindReverseProxyConfig.java diff --git a/.github/workflows/on-release-tag.yml b/.github/workflows/on-release-tag.yml index 349284f..cb19471 100644 --- a/.github/workflows/on-release-tag.yml +++ b/.github/workflows/on-release-tag.yml @@ -64,6 +64,9 @@ jobs: permissions: contents: read packages: write + defaults: + run: + working-directory: ./frontend steps: - uses: actions/checkout@v5 @@ -94,7 +97,7 @@ jobs: --build-arg VERSION=${VERSION} \ -t ghcr.io/hackyourfuture/course-hub-frontend:${{ steps.get-version.outputs.version }} \ -t ghcr.io/hackyourfuture/course-hub-frontend:latest \ - frontend + . if [ "$DOCKER_PUSH" = "true" ]; then docker push ghcr.io/hackyourfuture/course-hub-frontend:${{ steps.get-version.outputs.version }} docker push ghcr.io/hackyourfuture/course-hub-frontend:latest diff --git a/backend/src/main/java/net/hackyourfuture/coursehub/CourseHubApplication.java b/backend/src/main/java/net/hackyourfuture/coursehub/CourseHubApplication.java index 54bdceb..566f240 100644 --- a/backend/src/main/java/net/hackyourfuture/coursehub/CourseHubApplication.java +++ b/backend/src/main/java/net/hackyourfuture/coursehub/CourseHubApplication.java @@ -8,5 +8,4 @@ public class CourseHubApplication { public static void main(String[] args) { SpringApplication.run(CourseHubApplication.class, args); } - } diff --git a/backend/src/main/java/net/hackyourfuture/coursehub/SwaggerBehindReverseProxyConfig.java b/backend/src/main/java/net/hackyourfuture/coursehub/SwaggerBehindReverseProxyConfig.java deleted file mode 100644 index 57b71d3..0000000 --- a/backend/src/main/java/net/hackyourfuture/coursehub/SwaggerBehindReverseProxyConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.hackyourfuture.coursehub; - -import org.springdoc.core.customizers.ServerBaseUrlCustomizer; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * This configuration adjusts Swagger URLs when the application is running behind a reverse proxy on Digital Ocean. - */ -@Configuration -public class SwaggerBehindReverseProxyConfig { - - @Value("${open-api.suffix:#{environment.OPEN_API_SUFFIX}}") - private String openApiSuffix; - - @Bean - ServerBaseUrlCustomizer serverBaseUrlCustomizer() { - return (serverBaseUrl, request) -> serverBaseUrl + openApiSuffix; - } -} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index b5057e2..f23a310 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -8,12 +8,10 @@ spring.datasource.password=course_user_password # Server configuration server.port=8080 +# Configuration for handling forwarded headers (like X-Forwarded-For) +server.forward-headers-strategy=framework # Session in Redis Configuration # We want users to stay logged in for 7 days for convenience spring.session.timeout=7d -open-api.suffix=/api - -springdoc.swagger-ui.url=${open-api.suffix}/v3/api-docs -springdoc.swagger-ui.config-url=${open-api.suffix}/v3/api-docs/swagger-config diff --git a/deployment/README.md b/deployment/README.md index 20379d2..eb48f06 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -22,7 +22,7 @@ ssh user@server cd /opt/course-hub ``` -Docker status +Docker status: ```bash docker stats ``` diff --git a/deployment/docker-compose.yaml b/deployment/docker-compose.yaml index 471fece..e4f2b75 100644 --- a/deployment/docker-compose.yaml +++ b/deployment/docker-compose.yaml @@ -17,7 +17,7 @@ services: condition: service_started course-hub-frontend: condition: service_started - + # Postgres, main data store used by course-hub-backend postgres: image: postgres:18 @@ -31,7 +31,7 @@ services: - postgres:/var/lib/postgresql ports: - "5432:5432" - + # Redis, auth session storage used by course-hub-backend redis: image: redis:7 @@ -46,23 +46,22 @@ services: restart: on-failure environment: BACKEND_URL: https://coursehub.hyf.dev/api - + course-hub-backend: image: ghcr.io/hackyourfuture/course-hub-backend:latest container_name: course-hub-backend restart: on-failure environment: - JVM_TOOL_OPTS: -XX:ReservedCodeCacheSize=120M + JAVA_OPTS: -XX:ReservedCodeCacheSize=120M BPL_JVM_THREAD_COUNT: 20 SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/coursehub SPRING_DATA_REDIS_HOST: redis - OPEN_API_SUFFIX: /api depends_on: postgres: condition: service_started redis: condition: service_started - + # Agent that monitors whenever new versions of images are published and recreates the containers watchtower: image: containrrr/watchtower diff --git a/deployment/nginx.conf b/deployment/nginx.conf index dda1451..f572f75 100644 --- a/deployment/nginx.conf +++ b/deployment/nginx.conf @@ -10,6 +10,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Prefix /api; } location / {