The server supports both HTTP and HTTPS modes with automatic TLS configuration, secure session management, and production-ready certificate handling.
The server uses environment variables for configuration (see .env file):
# Basic server settings
SERVER_HOST=127.0.0.1
SERVER_PORT=8080
# TLS Configuration
ENABLE_TLS=true
GENERATE_SELF_SIGNED_CERT=true # Development mode
TLS_CERT_PATH=./certs/cert.pem # Production mode
TLS_KEY_PATH=./certs/private.pem # Production mode
TLS_CERT_DIR=certs
# CORS settings for frontend integration
CORS_ENABLED=true
CORS_ORIGINS=https://localhost:4200,https://localhost:3000,http://localhost:4200,http://localhost:3000For development, the server automatically generates self-signed certificates:
# Certificates generated automatically on startup
# Location: ./certs/
# - cert.pem (certificate)
# - private.pem (private key)# HTTPS (when ENABLE_TLS=true)
https://localhost:8080/swagger-ui/
https://localhost:8080/health
# HTTP (when ENABLE_TLS=false)
http://localhost:8080/swagger-ui/
http://localhost:8080/healthFor production, provide your own certificates via environment variables:
# Production environment
ENABLE_TLS=true
GENERATE_SELF_SIGNED_CERT=false
TLS_CERT_PATH=/etc/ssl/certs/your-domain.pem
TLS_KEY_PATH=/etc/ssl/private/your-domain.key
CORS_ORIGINS=https://your-frontend-domain.com- Format: PEM-encoded certificates
- Chain: Include intermediate certificates if required
- Permissions: Ensure proper file permissions (600 for private key)
When HTTPS is enabled, session cookies are automatically configured with:
- HttpOnly: Prevents XSS access to cookies
- SameSite=Lax: CSRF protection while allowing cross-site navigation
- Secure: Ensures cookies are only sent over HTTPS
For security with credentials enabled:
- Specific Origins: No wildcard (*) allowed with credentials
- Explicit Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
- Allowed Headers: Authorization, Content-Type, X-Requested-With, Accept, Origin, X-CSRF-Token
# Check certificate details
openssl x509 -in ./certs/cert.pem -text -noout
# Test HTTPS connection
curl -I https://localhost:8080/health --insecure# Login and capture session cookie
curl -X POST https://localhost:8080/auth/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "password"}' \
-c cookies.txt --insecure
# Use session cookie for authenticated request
curl https://localhost:8080/auth/api/me \
-b cookies.txt --insecureThe server includes comprehensive HTTPS integration tests:
# Run HTTPS integration tests
cargo test --test https_integration_tests
# Test coverage includes:
# - Self-signed certificate generation
# - Custom certificate loading
# - TLS configuration validation
# - CORS security compliance
# - Session cookie securityCertificate Permission Errors
# Fix private key permissions
chmod 600 /path/to/private.key
chown server-user:server-group /path/to/private.keyCORS Preflight Failures
- Ensure frontend origin is listed in
cors_origins - Verify HTTPS/HTTP protocol match between frontend and backend
- Check that credentials are enabled in frontend requests
Self-Signed Certificate Warnings
- Expected behavior in development
- Use
--insecureflag with curl for testing - Import certificate to browser trust store for local development