This commit is contained in:
johnpccd 2025-05-24 22:52:25 +02:00
parent bfa1292b05
commit 9814c334e5
7 changed files with 269 additions and 70 deletions

View File

@ -44,7 +44,7 @@ spec:
- name: LOG_LEVEL - name: LOG_LEVEL
value: "INFO" value: "INFO"
- name: CORS_ORIGINS - name: CORS_ORIGINS
value: "*" value: "['*']"
- name: CORS_METHODS - name: CORS_METHODS
value: "GET,POST,PUT,DELETE,OPTIONS" value: "GET,POST,PUT,DELETE,OPTIONS"
- name: CORS_HEADERS - name: CORS_HEADERS

View File

@ -0,0 +1 @@
{"ID":"5f252024-676f-4920-f829-cb47c30360a4","Operation":"OperationTypeApply","Info":"","Who":"DESKTOP\\habal@Desktop","Version":"1.10.1","Created":"2025-05-24T20:52:18.4005055Z","Path":"terraform.tfstate"}

View File

@ -115,10 +115,46 @@ resource "google_cloud_run_service" "sereact" {
value = var.qdrant_api_key value = var.qdrant_api_key
} }
env {
name = "QDRANT_HTTPS"
value = "false"
}
env {
name = "QDRANT_PREFER_GRPC"
value = "false"
}
env { env {
name = "LOG_LEVEL" name = "LOG_LEVEL"
value = "INFO" value = "INFO"
} }
# CORS Configuration - These were missing!
env {
name = "CORS_ORIGINS"
value = "['*']"
}
env {
name = "CORS_METHODS"
value = "GET,POST,PUT,DELETE,OPTIONS"
}
env {
name = "CORS_HEADERS"
value = "Content-Type,Authorization,X-Requested-With"
}
env {
name = "CORS_EXPOSE_HEADERS"
value = "Content-Length,Content-Range"
}
env {
name = "CORS_MAX_AGE"
value = "3600"
}
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"version": 4, "version": 4,
"terraform_version": "1.10.1", "terraform_version": "1.10.1",
"serial": 260, "serial": 269,
"lineage": "a183cd95-f987-8698-c6dd-84e933c394a5", "lineage": "a183cd95-f987-8698-c6dd-84e933c394a5",
"outputs": { "outputs": {
"cloud_run_qdrant_host": { "cloud_run_qdrant_host": {
@ -136,7 +136,7 @@
"effective_annotations": { "effective_annotations": {
"run.googleapis.com/ingress": "all", "run.googleapis.com/ingress": "all",
"run.googleapis.com/ingress-status": "all", "run.googleapis.com/ingress-status": "all",
"run.googleapis.com/operation-id": "5c612fa4-f8c2-4757-88a1-c0c2fe67d0ad", "run.googleapis.com/operation-id": "a36b6733-8ef6-4151-a609-3f89a8666953",
"run.googleapis.com/urls": "[\"https://sereact-761163285547.us-central1.run.app\",\"https://sereact-p64zpdtkta-uc.a.run.app\"]", "run.googleapis.com/urls": "[\"https://sereact-761163285547.us-central1.run.app\",\"https://sereact-p64zpdtkta-uc.a.run.app\"]",
"serving.knative.dev/creator": "johnpccd3@gmail.com", "serving.knative.dev/creator": "johnpccd3@gmail.com",
"serving.knative.dev/lastModifier": "johnpccd3@gmail.com" "serving.knative.dev/lastModifier": "johnpccd3@gmail.com"
@ -145,10 +145,10 @@
"cloud.googleapis.com/location": "us-central1", "cloud.googleapis.com/location": "us-central1",
"goog-terraform-provisioned": "true" "goog-terraform-provisioned": "true"
}, },
"generation": 1, "generation": 4,
"labels": null, "labels": {},
"namespace": "gen-lang-client-0424120530", "namespace": "gen-lang-client-0424120530",
"resource_version": "AAY15bM0evU", "resource_version": "AAY159zQkzU",
"self_link": "/apis/serving.knative.dev/v1/namespaces/761163285547/services/sereact", "self_link": "/apis/serving.knative.dev/v1/namespaces/761163285547/services/sereact",
"terraform_labels": { "terraform_labels": {
"goog-terraform-provisioned": "true" "goog-terraform-provisioned": "true"
@ -162,27 +162,27 @@
{ {
"conditions": [ "conditions": [
{ {
"message": "", "message": "Revision 'sereact-00004-45z' is not ready and cannot serve traffic. The user-provided container failed the configured startup probe checks. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=gen-lang-client-0424120530\u0026resource=cloud_run_revision/service_name/sereact/revision_name/sereact-00004-45z\u0026advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22sereact%22%0Aresource.labels.revision_name%3D%22sereact-00004-45z%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
"reason": "", "reason": "HealthCheckContainerError",
"status": "True", "status": "False",
"type": "Ready" "type": "Ready"
}, },
{ {
"message": "", "message": "The user-provided container failed the configured startup probe checks. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=gen-lang-client-0424120530\u0026resource=cloud_run_revision/service_name/sereact/revision_name/sereact-00003-2fs\u0026advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22sereact%22%0Aresource.labels.revision_name%3D%22sereact-00003-2fs%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
"reason": "", "reason": "",
"status": "True", "status": "True",
"type": "ConfigurationsReady" "type": "ConfigurationsReady"
}, },
{ {
"message": "", "message": "Revision 'sereact-00004-45z' is not ready and cannot serve traffic. The user-provided container failed the configured startup probe checks. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=gen-lang-client-0424120530\u0026resource=cloud_run_revision/service_name/sereact/revision_name/sereact-00004-45z\u0026advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22sereact%22%0Aresource.labels.revision_name%3D%22sereact-00004-45z%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
"reason": "", "reason": "HealthCheckContainerError",
"status": "True", "status": "False",
"type": "RoutesReady" "type": "RoutesReady"
} }
], ],
"latest_created_revision_name": "sereact-00001-rsq", "latest_created_revision_name": "sereact-00004-45z",
"latest_ready_revision_name": "sereact-00001-rsq", "latest_ready_revision_name": "sereact-00001-rsq",
"observed_generation": 1, "observed_generation": 4,
"traffic": [ "traffic": [
{ {
"latest_revision": true, "latest_revision": true,
@ -204,7 +204,7 @@
}, },
"generation": 0, "generation": 0,
"labels": { "labels": {
"run.googleapis.com/startupProbeType": "Default" "run.googleapis.com/startupProbeType": "Custom"
}, },
"name": "", "name": "",
"namespace": "", "namespace": "",
@ -218,9 +218,34 @@
"container_concurrency": 80, "container_concurrency": 80,
"containers": [ "containers": [
{ {
"args": null, "args": [],
"command": null, "command": [],
"env": [ "env": [
{
"name": "CORS_EXPOSE_HEADERS",
"value": "Content-Length,Content-Range",
"value_from": []
},
{
"name": "CORS_HEADERS",
"value": "Content-Type,Authorization,X-Requested-With",
"value_from": []
},
{
"name": "CORS_MAX_AGE",
"value": "3600",
"value_from": []
},
{
"name": "CORS_METHODS",
"value": "GET,POST,PUT,DELETE,OPTIONS",
"value_from": []
},
{
"name": "CORS_ORIGINS",
"value": "['*']",
"value_from": []
},
{ {
"name": "FIRESTORE_DATABASE_NAME", "name": "FIRESTORE_DATABASE_NAME",
"value": "sereact-imagedb", "value": "sereact-imagedb",
@ -251,11 +276,21 @@
"value": "34.71.6.1", "value": "34.71.6.1",
"value_from": [] "value_from": []
}, },
{
"name": "QDRANT_HTTPS",
"value": "false",
"value_from": []
},
{ {
"name": "QDRANT_PORT", "name": "QDRANT_PORT",
"value": "6333", "value": "6333",
"value_from": [] "value_from": []
}, },
{
"name": "QDRANT_PREFER_GRPC",
"value": "false",
"value_from": []
},
{ {
"name": "VECTOR_DB_ENVIRONMENT", "name": "VECTOR_DB_ENVIRONMENT",
"value": "gcp-starter", "value": "gcp-starter",
@ -284,29 +319,31 @@
"cpu": "1", "cpu": "1",
"memory": "1Gi" "memory": "1Gi"
}, },
"requests": null "requests": {}
} }
], ],
"startup_probe": [ "startup_probe": [
{ {
"failure_threshold": 1, "failure_threshold": 6,
"grpc": [], "grpc": [],
"http_get": [], "http_get": [
"initial_delay_seconds": 0,
"period_seconds": 240,
"tcp_socket": [
{ {
"http_headers": [],
"path": "/health",
"port": 8000 "port": 8000
} }
], ],
"timeout_seconds": 240 "initial_delay_seconds": 30,
"period_seconds": 10,
"tcp_socket": [],
"timeout_seconds": 5
} }
], ],
"volume_mounts": [], "volume_mounts": [],
"working_dir": "" "working_dir": ""
} }
], ],
"node_selector": null, "node_selector": {},
"service_account_name": "761163285547-compute@developer.gserviceaccount.com", "service_account_name": "761163285547-compute@developer.gserviceaccount.com",
"serving_state": "", "serving_state": "",
"timeout_seconds": 300, "timeout_seconds": 300,
@ -407,13 +444,6 @@
} }
] ]
}, },
{
"mode": "managed",
"type": "google_compute_address",
"name": "vector_db_static_ip",
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
"instances": []
},
{ {
"mode": "managed", "mode": "managed",
"type": "google_compute_firewall", "type": "google_compute_firewall",
@ -620,6 +650,12 @@
"zone": "us-central1-a" "zone": "us-central1-a"
}, },
"sensitive_attributes": [ "sensitive_attributes": [
[
{
"type": "get_attr",
"value": "metadata_startup_script"
}
],
[ [
{ {
"type": "get_attr", "type": "get_attr",
@ -653,12 +689,6 @@
"type": "get_attr", "type": "get_attr",
"value": "disk_encryption_key_rsa" "value": "disk_encryption_key_rsa"
} }
],
[
{
"type": "get_attr",
"value": "metadata_startup_script"
}
] ]
], ],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiNiJ9", "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiNiJ9",
@ -686,8 +716,8 @@
"database_edition": "STANDARD", "database_edition": "STANDARD",
"delete_protection_state": "DELETE_PROTECTION_DISABLED", "delete_protection_state": "DELETE_PROTECTION_DISABLED",
"deletion_policy": "ABANDON", "deletion_policy": "ABANDON",
"earliest_version_time": "2025-05-24T17:16:21.411338Z", "earliest_version_time": "2025-05-24T19:50:39.508594Z",
"etag": "IM/W7rHbvI0DMLa2lbPIvI0D", "etag": "ILqLvPD9vI0DMLa2lbPIvI0D",
"id": "projects/gen-lang-client-0424120530/databases/sereact-imagedb", "id": "projects/gen-lang-client-0424120530/databases/sereact-imagedb",
"key_prefix": "", "key_prefix": "",
"location_id": "us-central1", "location_id": "us-central1",
@ -701,7 +731,10 @@
"version_retention_period": "3600s" "version_retention_period": "3600s"
}, },
"sensitive_attributes": [], "sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMCJ9" "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMCJ9",
"dependencies": [
"google_project_service.services"
]
} }
] ]
}, },

View File

@ -1,7 +1,7 @@
{ {
"version": 4, "version": 4,
"terraform_version": "1.10.1", "terraform_version": "1.10.1",
"serial": 259, "serial": 268,
"lineage": "a183cd95-f987-8698-c6dd-84e933c394a5", "lineage": "a183cd95-f987-8698-c6dd-84e933c394a5",
"outputs": { "outputs": {
"cloud_run_qdrant_host": { "cloud_run_qdrant_host": {
@ -41,6 +41,10 @@
} }
] ]
}, },
"firestore_database_id": {
"value": "projects/gen-lang-client-0424120530/databases/sereact-imagedb",
"type": "string"
},
"pubsub_dlq_topic_name": { "pubsub_dlq_topic_name": {
"value": "image-processing-topic-dlq", "value": "image-processing-topic-dlq",
"type": "string" "type": "string"
@ -132,7 +136,7 @@
"effective_annotations": { "effective_annotations": {
"run.googleapis.com/ingress": "all", "run.googleapis.com/ingress": "all",
"run.googleapis.com/ingress-status": "all", "run.googleapis.com/ingress-status": "all",
"run.googleapis.com/operation-id": "5c612fa4-f8c2-4757-88a1-c0c2fe67d0ad", "run.googleapis.com/operation-id": "25c8aa08-3810-4d26-82c7-5fa64300fdf9",
"run.googleapis.com/urls": "[\"https://sereact-761163285547.us-central1.run.app\",\"https://sereact-p64zpdtkta-uc.a.run.app\"]", "run.googleapis.com/urls": "[\"https://sereact-761163285547.us-central1.run.app\",\"https://sereact-p64zpdtkta-uc.a.run.app\"]",
"serving.knative.dev/creator": "johnpccd3@gmail.com", "serving.knative.dev/creator": "johnpccd3@gmail.com",
"serving.knative.dev/lastModifier": "johnpccd3@gmail.com" "serving.knative.dev/lastModifier": "johnpccd3@gmail.com"
@ -141,10 +145,10 @@
"cloud.googleapis.com/location": "us-central1", "cloud.googleapis.com/location": "us-central1",
"goog-terraform-provisioned": "true" "goog-terraform-provisioned": "true"
}, },
"generation": 1, "generation": 3,
"labels": null, "labels": {},
"namespace": "gen-lang-client-0424120530", "namespace": "gen-lang-client-0424120530",
"resource_version": "AAY15bM0evU", "resource_version": "AAY15dY3+48",
"self_link": "/apis/serving.knative.dev/v1/namespaces/761163285547/services/sereact", "self_link": "/apis/serving.knative.dev/v1/namespaces/761163285547/services/sereact",
"terraform_labels": { "terraform_labels": {
"goog-terraform-provisioned": "true" "goog-terraform-provisioned": "true"
@ -158,27 +162,27 @@
{ {
"conditions": [ "conditions": [
{ {
"message": "", "message": "Revision 'sereact-00003-2fs' is not ready and cannot serve traffic. The user-provided container failed the configured startup probe checks. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=gen-lang-client-0424120530\u0026resource=cloud_run_revision/service_name/sereact/revision_name/sereact-00003-2fs\u0026advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22sereact%22%0Aresource.labels.revision_name%3D%22sereact-00003-2fs%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
"reason": "", "reason": "HealthCheckContainerError",
"status": "True", "status": "False",
"type": "Ready" "type": "Ready"
}, },
{ {
"message": "", "message": "The user-provided container failed the configured startup probe checks. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=gen-lang-client-0424120530\u0026resource=cloud_run_revision/service_name/sereact/revision_name/sereact-00003-2fs\u0026advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22sereact%22%0Aresource.labels.revision_name%3D%22sereact-00003-2fs%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
"reason": "", "reason": "",
"status": "True", "status": "True",
"type": "ConfigurationsReady" "type": "ConfigurationsReady"
}, },
{ {
"message": "", "message": "Revision 'sereact-00003-2fs' is not ready and cannot serve traffic. The user-provided container failed the configured startup probe checks. Logs for this revision might contain more information.\n\nLogs URL: https://console.cloud.google.com/logs/viewer?project=gen-lang-client-0424120530\u0026resource=cloud_run_revision/service_name/sereact/revision_name/sereact-00003-2fs\u0026advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22sereact%22%0Aresource.labels.revision_name%3D%22sereact-00003-2fs%22 \nFor more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start",
"reason": "", "reason": "HealthCheckContainerError",
"status": "True", "status": "False",
"type": "RoutesReady" "type": "RoutesReady"
} }
], ],
"latest_created_revision_name": "sereact-00001-rsq", "latest_created_revision_name": "sereact-00003-2fs",
"latest_ready_revision_name": "sereact-00001-rsq", "latest_ready_revision_name": "sereact-00001-rsq",
"observed_generation": 1, "observed_generation": 3,
"traffic": [ "traffic": [
{ {
"latest_revision": true, "latest_revision": true,
@ -200,7 +204,7 @@
}, },
"generation": 0, "generation": 0,
"labels": { "labels": {
"run.googleapis.com/startupProbeType": "Default" "run.googleapis.com/startupProbeType": "Custom"
}, },
"name": "", "name": "",
"namespace": "", "namespace": "",
@ -214,9 +218,34 @@
"container_concurrency": 80, "container_concurrency": 80,
"containers": [ "containers": [
{ {
"args": null, "args": [],
"command": null, "command": [],
"env": [ "env": [
{
"name": "CORS_EXPOSE_HEADERS",
"value": "Content-Length,Content-Range",
"value_from": []
},
{
"name": "CORS_HEADERS",
"value": "Content-Type,Authorization,X-Requested-With",
"value_from": []
},
{
"name": "CORS_MAX_AGE",
"value": "3600",
"value_from": []
},
{
"name": "CORS_METHODS",
"value": "GET,POST,PUT,DELETE,OPTIONS",
"value_from": []
},
{
"name": "CORS_ORIGINS",
"value": "['*']",
"value_from": []
},
{ {
"name": "FIRESTORE_DATABASE_NAME", "name": "FIRESTORE_DATABASE_NAME",
"value": "sereact-imagedb", "value": "sereact-imagedb",
@ -247,11 +276,21 @@
"value": "34.71.6.1", "value": "34.71.6.1",
"value_from": [] "value_from": []
}, },
{
"name": "QDRANT_HTTPS",
"value": "false",
"value_from": []
},
{ {
"name": "QDRANT_PORT", "name": "QDRANT_PORT",
"value": "6333", "value": "6333",
"value_from": [] "value_from": []
}, },
{
"name": "QDRANT_PREFER_GRPC",
"value": "false",
"value_from": []
},
{ {
"name": "VECTOR_DB_ENVIRONMENT", "name": "VECTOR_DB_ENVIRONMENT",
"value": "gcp-starter", "value": "gcp-starter",
@ -280,29 +319,31 @@
"cpu": "1", "cpu": "1",
"memory": "1Gi" "memory": "1Gi"
}, },
"requests": null "requests": {}
} }
], ],
"startup_probe": [ "startup_probe": [
{ {
"failure_threshold": 1, "failure_threshold": 6,
"grpc": [], "grpc": [],
"http_get": [], "http_get": [
"initial_delay_seconds": 0,
"period_seconds": 240,
"tcp_socket": [
{ {
"http_headers": [],
"path": "/health",
"port": 8000 "port": 8000
} }
], ],
"timeout_seconds": 240 "initial_delay_seconds": 30,
"period_seconds": 10,
"tcp_socket": [],
"timeout_seconds": 5
} }
], ],
"volume_mounts": [], "volume_mounts": [],
"working_dir": "" "working_dir": ""
} }
], ],
"node_selector": null, "node_selector": {},
"service_account_name": "761163285547-compute@developer.gserviceaccount.com", "service_account_name": "761163285547-compute@developer.gserviceaccount.com",
"serving_state": "", "serving_state": "",
"timeout_seconds": 300, "timeout_seconds": 300,
@ -666,6 +707,44 @@
} }
] ]
}, },
{
"mode": "managed",
"type": "google_firestore_database",
"name": "database",
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"app_engine_integration_mode": "DISABLED",
"cmek_config": [],
"concurrency_mode": "PESSIMISTIC",
"create_time": "",
"database_edition": "STANDARD",
"delete_protection_state": "DELETE_PROTECTION_DISABLED",
"deletion_policy": "ABANDON",
"earliest_version_time": "2025-05-24T19:50:07.050995Z",
"etag": "IKWD/+D9vI0DMLa2lbPIvI0D",
"id": "projects/gen-lang-client-0424120530/databases/sereact-imagedb",
"key_prefix": "",
"location_id": "us-central1",
"name": "sereact-imagedb",
"point_in_time_recovery_enablement": "POINT_IN_TIME_RECOVERY_DISABLED",
"project": "gen-lang-client-0424120530",
"timeouts": null,
"type": "FIRESTORE_NATIVE",
"uid": "30634721-c8c7-4673-b605-c1a91dff3eab",
"update_time": "",
"version_retention_period": "3600s"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMCJ9",
"dependencies": [
"google_project_service.services"
]
}
]
},
{ {
"mode": "managed", "mode": "managed",
"type": "google_project_service", "type": "google_project_service",

View File

@ -68,8 +68,10 @@ app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=settings.CORS_ORIGINS, allow_origins=settings.CORS_ORIGINS,
allow_credentials=True, allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], allow_methods=settings.CORS_METHODS,
allow_headers=["Content-Type", "Authorization", "X-API-Key"], allow_headers=settings.CORS_HEADERS,
expose_headers=settings.CORS_EXPOSE_HEADERS,
max_age=settings.CORS_MAX_AGE,
) )
# Include API routers # Include API routers

View File

@ -12,14 +12,62 @@ class Settings(BaseSettings):
ENVIRONMENT: str = "development" ENVIRONMENT: str = "development"
# CORS settings # CORS settings
CORS_ORIGINS: List[str] = ["http://localhost:3000", "http://localhost:8000", "http://127.0.0.1:8000", "http://127.0.0.1:3000", "https://localhost:3000", "https://localhost:8000"] CORS_ORIGINS: List[str] = ["*"]
CORS_METHODS: List[str] = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
CORS_HEADERS: List[str] = ["Content-Type", "Authorization", "X-Requested-With"]
CORS_EXPOSE_HEADERS: List[str] = ["Content-Length", "Content-Range"]
CORS_MAX_AGE: int = 3600
@field_validator("CORS_ORIGINS", mode="before") @field_validator("CORS_ORIGINS", mode="before")
def assemble_cors_origins(cls, v): def assemble_cors_origins(cls, v):
# Read from environment variable first
env_origins = os.getenv("CORS_ORIGINS")
if env_origins:
if env_origins.startswith("[") and env_origins.endswith("]"):
# Handle list format like "['*']"
import ast
try:
return ast.literal_eval(env_origins)
except:
pass
# Handle comma-separated format
return [i.strip().strip("'\"") for i in env_origins.split(",")]
# Fallback to default if no env var
if isinstance(v, str) and not v.startswith("["): if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")] return [i.strip() for i in v.split(",")]
elif not v: # If empty list, use defaults
return ["http://localhost:3000", "http://localhost:8000", "http://127.0.0.1:8000", "http://127.0.0.1:3000", "https://localhost:3000", "https://localhost:8000"]
return v return v
@field_validator("CORS_METHODS", mode="before")
def assemble_cors_methods(cls, v):
env_methods = os.getenv("CORS_METHODS")
if env_methods:
return [i.strip() for i in env_methods.split(",")]
return v or ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
@field_validator("CORS_HEADERS", mode="before")
def assemble_cors_headers(cls, v):
env_headers = os.getenv("CORS_HEADERS")
if env_headers:
return [i.strip() for i in env_headers.split(",")]
return v or ["Content-Type", "Authorization", "X-Requested-With"]
@field_validator("CORS_EXPOSE_HEADERS", mode="before")
def assemble_cors_expose_headers(cls, v):
env_expose = os.getenv("CORS_EXPOSE_HEADERS")
if env_expose:
return [i.strip() for i in env_expose.split(",")]
return v or ["Content-Length", "Content-Range"]
@field_validator("CORS_MAX_AGE", mode="before")
def assemble_cors_max_age(cls, v):
env_max_age = os.getenv("CORS_MAX_AGE")
if env_max_age:
return int(env_max_age)
return v or 3600
# Firestore settings # Firestore settings
FIRESTORE_PROJECT_ID: str = os.getenv("FIRESTORE_PROJECT_ID", "") FIRESTORE_PROJECT_ID: str = os.getenv("FIRESTORE_PROJECT_ID", "")
FIRESTORE_DATABASE_NAME: str = os.getenv("FIRESTORE_DATABASE_NAME", "sereact-db") FIRESTORE_DATABASE_NAME: str = os.getenv("FIRESTORE_DATABASE_NAME", "sereact-db")