Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ jobs:
TF_VAR_ses_email: ${{ secrets.SES_EMAIL }}
TF_VAR_supabase_url: ${{ secrets.SUPABASE_URL }}
TF_VAR_supabase_jwt_secret: ${{ secrets.SUPABASE_JWT_SECRET }}
TF_VAR_domain_name: ${{ secrets.DOMAIN_NAME }}
TF_VAR_environment: staging
run: terraform plan -out=tfplan

Expand All @@ -169,6 +170,7 @@ jobs:
TF_VAR_ses_email: ${{ secrets.SES_EMAIL }}
TF_VAR_supabase_url: ${{ secrets.SUPABASE_URL }}
TF_VAR_supabase_jwt_secret: ${{ secrets.SUPABASE_JWT_SECRET }}
TF_VAR_domain_name: ${{ secrets.DOMAIN_NAME }}
TF_VAR_environment: staging
run: terraform apply -auto-approve tfplan

Expand Down Expand Up @@ -277,6 +279,7 @@ jobs:
TF_VAR_ses_email: ${{ secrets.SES_EMAIL }}
TF_VAR_supabase_url: ${{ secrets.SUPABASE_URL }}
TF_VAR_supabase_jwt_secret: ${{ secrets.SUPABASE_JWT_SECRET }}
TF_VAR_domain_name: ${{ secrets.DOMAIN_NAME }}
TF_VAR_environment: prod
run: terraform plan -out=tfplan

Expand All @@ -286,6 +289,7 @@ jobs:
TF_VAR_ses_email: ${{ secrets.SES_EMAIL }}
TF_VAR_supabase_url: ${{ secrets.SUPABASE_URL }}
TF_VAR_supabase_jwt_secret: ${{ secrets.SUPABASE_JWT_SECRET }}
TF_VAR_domain_name: ${{ secrets.DOMAIN_NAME }}
TF_VAR_environment: prod
run: terraform apply -auto-approve tfplan

Expand Down
4 changes: 4 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ async def lifespan(app: FastAPI):
if settings.FRONTEND_URL:
origins.append(settings.FRONTEND_URL)

# Add CloudFront URL if using custom domain (both need to work)
if settings.CLOUDFRONT_URL and settings.CLOUDFRONT_URL not in origins:
origins.append(settings.CLOUDFRONT_URL)

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
Expand Down
1 change: 1 addition & 0 deletions backend/app/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Settings(BaseSettings):

# Frontend
FRONTEND_URL: str = "http://localhost:5173"
CLOUDFRONT_URL: str = "" # CloudFront URL when using custom domain

class Config:
env_file = ".env"
Expand Down
16 changes: 10 additions & 6 deletions terraform/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ resource "aws_lambda_function" "api" {
SUPABASE_URL = var.supabase_url
SUPABASE_JWT_SECRET = var.supabase_jwt_secret
SES_EMAIL = var.ses_email
FRONTEND_URL = "https://${aws_cloudfront_distribution.frontend.domain_name}"
FRONTEND_URL = var.domain_name != "" ? "https://${var.domain_name}" : "https://${aws_cloudfront_distribution.frontend.domain_name}"
CLOUDFRONT_URL = "https://${aws_cloudfront_distribution.frontend.domain_name}"
}
}

Expand Down Expand Up @@ -168,11 +169,14 @@ resource "aws_apigatewayv2_api" "main" {
allow_credentials = true
allow_headers = ["Content-Type", "Authorization", "X-Amz-Date", "X-Api-Key"]
allow_methods = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
allow_origins = [
"http://localhost:3000",
"http://localhost:5173",
"https://${aws_cloudfront_distribution.frontend.domain_name}"
]
allow_origins = concat(
[
"http://localhost:3000",
"http://localhost:5173",
"https://${aws_cloudfront_distribution.frontend.domain_name}"
],
var.domain_name != "" ? ["https://${var.domain_name}"] : []
)
expose_headers = ["*"]
max_age = 3600
}
Expand Down
13 changes: 8 additions & 5 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,14 @@ resource "aws_s3_bucket_cors_configuration" "attachments" {
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "PUT", "POST", "DELETE"]
allowed_origins = [
"http://localhost:3000",
"http://localhost:5173",
"https://${aws_cloudfront_distribution.frontend.domain_name}"
]
allowed_origins = concat(
[
"http://localhost:3000",
"http://localhost:5173",
"https://${aws_cloudfront_distribution.frontend.domain_name}"
],
var.domain_name != "" ? ["https://${var.domain_name}"] : []
)
expose_headers = ["ETag"]
max_age_seconds = 3000
}
Expand Down