Skip to content

Commit

Permalink
Merge pull request #48 from ppokrovskii:landing-cors
Browse files Browse the repository at this point in the history
chore: Add CORS headers to landing_backend.tf and contact_details.py
  • Loading branch information
ppokrovskii authored Jun 20, 2024
2 parents d8a84de + 9111b9f commit d828566
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions infra/runtime/function_app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "azurerm_service_plan" "resumematchpro" {
resource_group_name = azurerm_resource_group.rg.name
os_type = "Linux"
sku_name = "Y1"

# sku {
# tier = "Dynamic"
# size = "Y1"
Expand Down
11 changes: 10 additions & 1 deletion infra/runtime/landing_backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,29 @@ resource "azurerm_linux_function_app" "landing_backend" {
application_stack {
python_version = "3.11"
}

cors {
allowed_origins = ["https://${azurerm_static_web_app.landingpage.default_host_name}"]
}

}



app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python"
# "WEBSITE_RUN_FROM_PACKAGE" = ""
"APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.ResumeMatchProInsights.instrumentation_key
"AZURE_STORAGE_CONNECTION_STRING" = azurerm_storage_account.storage.primary_connection_string
"AzureWebJobsStorage" = azurerm_storage_account.storage.primary_connection_string

"ALLOW_ORIGIN" = "https://${azurerm_static_web_app.landingpage.default_host_name}"
"COSMOS_URL" = azurerm_cosmosdb_account.cosmosdb.endpoint
"COSMOS_KEY" = azurerm_cosmosdb_account.cosmosdb.primary_key
"COSMOS_DB_NAME" = "${var.project_name}-${terraform.workspace}-landing-backend"
}



tags = {
environment = terraform.workspace
}
Expand Down
11 changes: 11 additions & 0 deletions landing_backend/contact_details/contact_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ def get_contact_details(req: func.HttpRequest) -> func.HttpResponse:
many_contact_details_response = ManyContactDetailsResponse(contact_details=contact_details_responses)
return func.HttpResponse(many_contact_details_response.model_dump_json(exclude_none=True), status_code=200, mimetype="application/json")


# handle cors
@contact_details_bp.route("contact_details", methods=["OPTIONS"])
def handle_options(req: func.HttpRequest) -> func.HttpResponse:
logging.info('handle_options started')
ALLOW_ORIGIN = os.environ.get("ALLOW_ORIGIN", "*")
return func.HttpResponse(status_code=200, headers={
"Access-Control-Allow-Origin": "{ALLOW_ORIGIN}",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type"
})

0 comments on commit d828566

Please sign in to comment.