Backend Environment Variables
Backend environment variables are injected at runtime via the ECS Task Definition or Docker Compose configuration.Database Configuration
These variables configure the PostgreSQL database connection. In production, they should point to your AWS RDS instance.
| Variable | Required | Default | Description |
|---|---|---|---|
DB_HOST | Yes | localhost | PostgreSQL server hostname or IP address. In AWS, use your RDS endpoint (e.g., my-rds.xxxxx.eu-west-1.rds.amazonaws.com) |
DB_PORT | Yes | 5432 | PostgreSQL server port |
DB_NAME | Yes | urlshortener | Name of the database to connect to |
DB_USERNAME | Yes | postgres | Database user for authentication |
DB_PASSWORD | Yes | changeme | Database password for authentication |
JWT Configuration
JSON Web Tokens (JWT) are used for stateless authentication. The secret key must be at least 32 characters for HS256 signing.
| Variable | Required | Default | Description |
|---|---|---|---|
JWT_SECRET | Yes | changeme-this-must-be-at-least-32-chars-long!! | Secret key used to sign and verify JWT tokens. Must be at least 32 characters for HS256 algorithm |
JWT_EXPIRATION_MS | No | 86400000 | Token expiration time in milliseconds. Default is 24 hours (86400000 ms) |
Application URLs
| Variable | Required | Default | Description |
|---|---|---|---|
APP_BASE_URL | Yes | "" (empty string) | Base URL used when constructing fully-qualified short URLs returned in API responses. Must include protocol (e.g., https://go.yourdomain.com). If empty, falls back to the request’s context path |
FRONTEND_URL | No | http://localhost | Frontend application URL, used by the backend to construct redirect URLs to the SPA error pages |
When
APP_BASE_URL is not set, the backend will dynamically resolve the base URL from the incoming HTTP request. In production behind an ALB, you should explicitly set this to ensure consistent short URLs.CORS Configuration
Cross-Origin Resource Sharing (CORS) must be configured to allow the frontend to communicate with the backend API.
| Variable | Required | Default | Description |
|---|---|---|---|
CORS_ALLOWED_ORIGINS | Yes | http://localhost,http://localhost:3000,http://localhost:5173 | Comma-separated list of allowed origins for CORS requests. In production, set this to your frontend domain(s) only |
Server Configuration
| Variable | Required | Default | Description |
|---|---|---|---|
SERVER_PORT | No | 8080 | Port on which the Spring Boot application listens for HTTP requests |
Connection Pool Settings
HikariCP connection pool settings are configured in
application.yml and can be overridden via environment variables if needed.| Setting | Default | Description |
|---|---|---|
| Maximum Pool Size | 10 | Maximum number of connections in the pool |
| Minimum Idle | 2 | Minimum number of idle connections maintained |
| Connection Timeout | 30000 ms | Maximum time to wait for a connection from the pool |
application.yml but can be externalized if needed for production tuning.
Frontend Environment Variables
Build-Time Configuration
| Variable | Required | Default | Description |
|---|---|---|---|
VITE_API_BASE_URL | Yes | "" (empty string) | Base URL of the backend API. This value is embedded into the compiled JavaScript bundle at build time. Must include protocol (e.g., https://api.yourdomain.com) |
How It Works:
- Vite reads
VITE_API_BASE_URLfrom the environment during the build process - The value is replaced in the code via
import.meta.env.VITE_API_BASE_URL - The final JavaScript bundle contains the hardcoded URL
- This is accessed in
frontend/src/lib/api.ts:32
Setting Frontend Environment Variables
Local Development
Create a.env.local file in the frontend/ directory:
Docker Build
Pass as a build argument when building the Docker image:Docker Compose
Specified in thedocker-compose.yml file:
AWS ECS / CI/CD
In your GitHub Actions or CI/CD pipeline:Environment Variable Summary
Backend (Runtime Configuration)
Complete Backend Environment Variables
Complete Backend Environment Variables
Frontend (Build-Time Configuration)
Complete Frontend Build Arguments
Complete Frontend Build Arguments
AWS ECS Task Definition Example
Backend Task Definition Snippet
Backend Task Definition Snippet
Validation and Troubleshooting
Backend Startup Validation
The backend validates critical environment variables on startup:Common Startup Errors
Common Startup Errors
Error: Error:
The specified key byte array is X bits which is not secure enough for any JWT HMAC-SHA algorithmCause: JWT_SECRET is shorter than 32 characters (256 bits required for HS256)Solution: Generate a stronger secret:Connection refused or could not connect to serverCause: Database connection parameters are incorrect or database is unreachableSolution: Verify DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, and DB_PASSWORDError: Access denied for userCause: Invalid database credentialsSolution: Check DB_USERNAME and DB_PASSWORDFrontend Build Validation
Frontend Build Issues
Frontend Build Issues
Issue: API calls fail with CORS errorsCause:
CORS_ALLOWED_ORIGINS on backend doesn’t include frontend originSolution: Add frontend URL to backend’s CORS_ALLOWED_ORIGINSIssue: API calls go to wrong URLCause: VITE_API_BASE_URL was set incorrectly during buildSolution: Rebuild the frontend image with correct VITE_API_BASE_URLIssue: VITE_API_BASE_URL is undefinedCause: Build argument wasn’t passed to Docker buildSolution: Add --build-arg VITE_API_BASE_URL=<url> to docker build commandSecurity Best Practices
Related Documentation
- Business Rules - Application business logic and behaviors
- API Authentication - Authentication endpoints
- Deployment Guide - AWS infrastructure setup