Skip to content

Commit

Permalink
feat: [SRTP-43] add cors policy (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: petretiandrea <[email protected]>
  • Loading branch information
and-mora and petretiandrea authored Nov 5, 2024
1 parent a0ea006 commit 22e6712
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/rtp/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/rtp/01_apim_core.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ resource "azurerm_api_management_product_policy" "rtp_api_product" {
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

xml_content = file("./api_product/base_policy.xml")
xml_content = templatefile("./api_product/base_policy.xml", {
rtp_fe_origin = local.rtp_fe_origin,
dev_origin = var.env_short != "d" ? "" : "\n<origin>http://localhost:1234</origin>"
})
}

resource "azurerm_api_management_group" "rtp_group" {
Expand Down
3 changes: 2 additions & 1 deletion src/rtp/99_locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ locals {
apim_name = "${local.product}-apim"
apim_rg = "${local.product}-api-rg"

rtp_base_url = "https://api-rtp.${var.dns_zone_prefix}"
rtp_base_url = "https://api-rtp.${var.dns_zone_prefix}"
rtp_fe_origin = "${var.domain}.${var.dns_zone_prefix}"
}
1 change: 1 addition & 0 deletions src/rtp/api/pagopa/create_rtp_mock_policy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-->
<policies>
<inbound>
<base />
<set-variable name="uuid" value="@(Guid.NewGuid().ToString())"/>
<return-response>
<set-status code="200" reason="OK" />
Expand Down
15 changes: 14 additions & 1 deletion src/rtp/api_product/base_policy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@
-->
<policies>
<inbound>
<base />
<cors allow-credentials="true">
<allowed-origins>
<origin>https://${rtp_fe_origin}</origin>${dev_origin}
</allowed-origins>
<allowed-methods preflight-result-max-age="300">
<method>*</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
<expose-headers>
<header>*</header>
</expose-headers>
</cors>
</inbound>
<backend>
<base />
Expand Down

0 comments on commit 22e6712

Please sign in to comment.