add usage of environment variables

This commit is contained in:
2025-11-20 19:35:58 +00:00
parent cc56cd43e5
commit 807dea6854
3 changed files with 20 additions and 13 deletions

View File

@@ -19,7 +19,7 @@ func connectToPostgreSQL() (*gorm.DB, error) {
password := os.Getenv("POSTGRES_PASSWORD") password := os.Getenv("POSTGRES_PASSWORD")
dbname := os.Getenv("POSTGRES_DB") dbname := os.Getenv("POSTGRES_DB")
host := os.Getenv("POSTGRES_HOST") host := os.Getenv("POSTGRES_HOST")
port := os.Getenv("DB_PORT") port := os.Getenv("POSTGRES_PORT")
dsn := fmt.Sprintf( dsn := fmt.Sprintf(
"user=%s password=%s dbname=%s host=%s port=%s sslmode=disable", "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"}) c.JSON(200, gin.H{"message": "Hello World"})
}) })
port := os.Getenv("PORT") port := os.Getenv("BACKEND_PORT")
r.Run(fmt.Sprintf(":%s", port)) r.Run(fmt.Sprintf(":%s", port))
} }

View File

@@ -32,14 +32,14 @@ services:
build: build:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: backend container_name: "${BACKEND_HOST}"
restart: unless-stopped restart: unless-stopped
# ports:
# - "${BACKEND_PORT}:8080"
depends_on: depends_on:
- db - db
networks: networks:
- app-network - app-network
env_file:
- ./.env
db: db:
image: postgres:16 image: postgres:16
@@ -49,7 +49,5 @@ services:
POSTGRES_USER: "${POSTGRES_USER}" POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
POSTGRES_DB: "${POSTGRES_DB}" POSTGRES_DB: "${POSTGRES_DB}"
# ports:
# - "${DB_PORT}:5432"
networks: networks:
- app-network - app-network

View File

@@ -6,11 +6,20 @@ http {
server_tokens off; server_tokens off;
charset utf-8; charset utf-8;
server { server {
listen 80 default_server; listen 80;
server_name _; server_name adam-french.co.uk www.adam-french.co.uk;
return 301 https://$host$request_uri;
} # 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 { server {
@@ -29,7 +38,7 @@ http {
} }
location /posts/ { location /posts/ {
proxy_pass http://localhost:8080/posts; proxy_pass http://backend:8080/posts;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;