Skip to content

Commit

Permalink
feat: add cors to API endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Mar 5, 2024
1 parent d18b21f commit 106cb5a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions terraform/buckets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ resource "google_compute_backend_bucket" "modules" {
"Content-Security-Policy: default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';",
"x-jsr-cache-id: {cdn_cache_id}",
"x-jsr-cache-status: {cdn_cache_status}",
"access-control-allow-origin: *",
"access-control-expose-headers: *",
]
cdn_policy {
cache_mode = "USE_ORIGIN_HEADERS"
Expand Down
2 changes: 2 additions & 0 deletions terraform/cloud_run_api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ resource "google_compute_backend_service" "registry_api" {
custom_response_headers = [
"x-jsr-cache-id: {cdn_cache_id}",
"x-jsr-cache-status: {cdn_cache_status}",
"access-control-allow-origin: *",
"access-control-expose-headers: *",
]

enable_cdn = true
Expand Down
9 changes: 9 additions & 0 deletions terraform/https.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,19 @@ resource "google_compute_url_map" "frontend_https" {

path_matcher {
name = "api"

default_route_action {
url_rewrite {
path_prefix_rewrite = "/api"
}
cors_policy {
allow_methods = ["HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"]
allow_credentials = false
expose_headers = ["*"]
allow_origins = ["*"]
allow_headers = ["Authorization", "X-Cloud-Trace-Context"]
max_age = 3600
}
}
default_service = google_compute_backend_service.registry_api.self_link
}
Expand Down

0 comments on commit 106cb5a

Please sign in to comment.