From 807dea685438cc80719f10172fb65918ba9299c1 Mon Sep 17 00:00:00 2001 From: Adam French Date: Thu, 20 Nov 2025 19:35:58 +0000 Subject: [PATCH] add usage of environment variables --- backend/main.go | 4 ++-- docker-compose.yml | 8 +++----- nginx/nginx.conf | 21 +++++++++++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/backend/main.go b/backend/main.go index 8b03ff6..f9d8922 100644 --- a/backend/main.go +++ b/backend/main.go @@ -19,7 +19,7 @@ func connectToPostgreSQL() (*gorm.DB, error) { password := os.Getenv("POSTGRES_PASSWORD") dbname := os.Getenv("POSTGRES_DB") host := os.Getenv("POSTGRES_HOST") - port := os.Getenv("DB_PORT") + port := os.Getenv("POSTGRES_PORT") dsn := fmt.Sprintf( "user=%s password=%s dbname=%s host=%s port=%s sslmode=disable", @@ -72,6 +72,6 @@ func main() { c.JSON(200, gin.H{"message": "Hello World"}) }) - port := os.Getenv("PORT") + port := os.Getenv("BACKEND_PORT") r.Run(fmt.Sprintf(":%s", port)) } diff --git a/docker-compose.yml b/docker-compose.yml index 3149f5e..ff8380b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,14 +32,14 @@ services: build: context: ./backend dockerfile: Dockerfile - container_name: backend + container_name: "${BACKEND_HOST}" restart: unless-stopped - # ports: - # - "${BACKEND_PORT}:8080" depends_on: - db networks: - app-network + env_file: + - ./.env db: image: postgres:16 @@ -49,7 +49,5 @@ services: POSTGRES_USER: "${POSTGRES_USER}" POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" POSTGRES_DB: "${POSTGRES_DB}" - # ports: - # - "${DB_PORT}:5432" networks: - app-network diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 407e684..89eedee 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -6,11 +6,20 @@ http { server_tokens off; charset utf-8; - server { - listen 80 default_server; - server_name _; - return 301 https://$host$request_uri; - } + server { + listen 80; + server_name adam-french.co.uk www.adam-french.co.uk; + + # Allow Certbot to access the ACME challenge + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + # Redirect everything else to HTTPS + location / { + return 301 https://$host$request_uri; + } + } server { @@ -29,7 +38,7 @@ http { } location /posts/ { - proxy_pass http://localhost:8080/posts; + proxy_pass http://backend:8080/posts; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;