From 472fb52ece9e188537f3222c374d0ba999a2f7ca Mon Sep 17 00:00:00 2001 From: orpheusohms Date: Thu, 17 Apr 2025 12:01:48 +0100 Subject: [PATCH 1/5] added cloud docker-compose --- docker-compose-cloud.yml | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 docker-compose-cloud.yml diff --git a/docker-compose-cloud.yml b/docker-compose-cloud.yml new file mode 100644 index 00000000..f1af12df --- /dev/null +++ b/docker-compose-cloud.yml @@ -0,0 +1,67 @@ +version: "3.8" + +services: + postgres: + image: postgres:alpine + environment: + POSTGRES_DB: httpsms + POSTGRES_PASSWORD: dbpassword + POSTGRES_USER: dbusername + volumes: + - postgres:/var/lib/postgresql/data + ports: + - "5435:5432" + restart: on-failure + healthcheck: + test: ["CMD-SHELL", "pg_isready", "-U", "dbusername", "-d", "httpsms"] + interval: 30s + timeout: 60s + retries: 5 + start_period: 5s + networks: + - http-sms-network + + redis: + image: redis:latest + command: redis-server + volumes: + - redis:/var/lib/redis + ports: + - "6379:6379" + restart: on-failure + networks: + - http-sms-network + + api: + build: + context: ./api + ports: + - "8001:8000" + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_started + env_file: + - ./api/.env + networks: + - http-sms-network + + web: + build: + context: ./web + ports: + - "3001:3000" + depends_on: + api: + condition: service_started + networks: + - http-sms-network + +volumes: + redis: + postgres: + +networks: + http-sms-network: + external: true From 4067ad54548a43d3a4f27100041977620fdcff62 Mon Sep 17 00:00:00 2001 From: orpheusohms Date: Thu, 17 Apr 2025 12:43:29 +0100 Subject: [PATCH 2/5] added proxy pass to bypass cors --- web/nginx.conf | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/web/nginx.conf b/web/nginx.conf index 979fe802..8074a814 100644 --- a/web/nginx.conf +++ b/web/nginx.conf @@ -1,9 +1,19 @@ server { - listen 3000; - server_name localhost; - root /usr/share/nginx/html; - index index.html index.htm; -location / { - try_files $uri $uri/ /index.html; - } + listen 3000; + server_name localhost; + root /usr/share/nginx/html; + index index.html index.htm; + + location / { + try_files $uri $uri/ /index.html; + } + + # Proxy API requests to the Go API + location /api/ { + proxy_pass http://api-http-sms.zorvia.dev; # Use Docker service name and port + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } } From 48f27df93e0c5590bd68178276ea7bc5c6ad5831 Mon Sep 17 00:00:00 2001 From: orpheusohms Date: Thu, 17 Apr 2025 14:07:29 +0100 Subject: [PATCH 3/5] add cors config --- api/pkg/di/container.go | 19 +++++++++++- docker-compose-cloud.yml | 67 ---------------------------------------- 2 files changed, 18 insertions(+), 68 deletions(-) delete mode 100644 docker-compose-cloud.yml diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go index 6b54f63b..88c0adb8 100644 --- a/api/pkg/di/container.go +++ b/api/pkg/di/container.go @@ -153,6 +153,15 @@ func NewContainer(projectID string, version string) (container *Container) { return container } +func GetEnvWithDefault(key, defaultValue string) string { + value := os.Getenv(key) + if value == "" { + return defaultValue + } + + return value +} + // App creates a new instance of fiber.App func (container *Container) App() (app *fiber.App) { if container.app != nil { @@ -168,7 +177,15 @@ func (container *Container) App() (app *fiber.App) { } app.Use(otelfiber.Middleware()) - app.Use(cors.New()) + app.Use(cors.New( + cors.Config{ + AllowOrigins: GetEnvWithDefault("CORS_ALLOW_ORIGINS", "*"), + AllowHeaders: GetEnvWithDefault("CORS_ALLOW_HEADERS", "*"), + AllowMethods: GetEnvWithDefault("CORS_ALLOW_METHODS", "GET,POST,PUT,DELETE,OPTIONS"), + AllowCredentials: false, + ExposeHeaders: GetEnvWithDefault("CORS_EXPOSE_HEADERS", "*"), + })) + app.Use(middlewares.HTTPRequestLogger(container.Tracer(), container.Logger())) app.Use(middlewares.BearerAuth(container.Logger(), container.Tracer(), container.FirebaseAuthClient())) diff --git a/docker-compose-cloud.yml b/docker-compose-cloud.yml deleted file mode 100644 index f1af12df..00000000 --- a/docker-compose-cloud.yml +++ /dev/null @@ -1,67 +0,0 @@ -version: "3.8" - -services: - postgres: - image: postgres:alpine - environment: - POSTGRES_DB: httpsms - POSTGRES_PASSWORD: dbpassword - POSTGRES_USER: dbusername - volumes: - - postgres:/var/lib/postgresql/data - ports: - - "5435:5432" - restart: on-failure - healthcheck: - test: ["CMD-SHELL", "pg_isready", "-U", "dbusername", "-d", "httpsms"] - interval: 30s - timeout: 60s - retries: 5 - start_period: 5s - networks: - - http-sms-network - - redis: - image: redis:latest - command: redis-server - volumes: - - redis:/var/lib/redis - ports: - - "6379:6379" - restart: on-failure - networks: - - http-sms-network - - api: - build: - context: ./api - ports: - - "8001:8000" - depends_on: - postgres: - condition: service_healthy - redis: - condition: service_started - env_file: - - ./api/.env - networks: - - http-sms-network - - web: - build: - context: ./web - ports: - - "3001:3000" - depends_on: - api: - condition: service_started - networks: - - http-sms-network - -volumes: - redis: - postgres: - -networks: - http-sms-network: - external: true From d86e4fbc8c76b4edc21fdb18ef4c415050759b06 Mon Sep 17 00:00:00 2001 From: orpheusohms Date: Thu, 17 Apr 2025 14:08:39 +0100 Subject: [PATCH 4/5] remove proxy pass to bypass cors --- web/nginx.conf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/nginx.conf b/web/nginx.conf index 8074a814..ac31de9d 100644 --- a/web/nginx.conf +++ b/web/nginx.conf @@ -9,11 +9,11 @@ server { } # Proxy API requests to the Go API - location /api/ { - proxy_pass http://api-http-sms.zorvia.dev; # Use Docker service name and port - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } + # location /api/ { + # proxy_pass http://api-http-sms.zorvia.dev; # Use Docker service name and port + # proxy_http_version 1.1; + # proxy_set_header Host $host; + # proxy_set_header X-Real-IP $remote_addr; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # } } From 9d7f8e59fcfbbd18c05dbcceea706fce7e6aa530 Mon Sep 17 00:00:00 2001 From: orpheusohms Date: Thu, 17 Apr 2025 14:16:25 +0100 Subject: [PATCH 5/5] cleanup nginx fix removal --- web/nginx.conf | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/web/nginx.conf b/web/nginx.conf index ac31de9d..979fe802 100644 --- a/web/nginx.conf +++ b/web/nginx.conf @@ -1,19 +1,9 @@ server { - listen 3000; - server_name localhost; - root /usr/share/nginx/html; - index index.html index.htm; - - location / { - try_files $uri $uri/ /index.html; - } - - # Proxy API requests to the Go API - # location /api/ { - # proxy_pass http://api-http-sms.zorvia.dev; # Use Docker service name and port - # proxy_http_version 1.1; - # proxy_set_header Host $host; - # proxy_set_header X-Real-IP $remote_addr; - # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - # } + listen 3000; + server_name localhost; + root /usr/share/nginx/html; + index index.html index.htm; +location / { + try_files $uri $uri/ /index.html; + } }