此文已使用 Salesforce 機器翻譯系統翻譯。更多詳細資料請參見此處。
分階段無頭式部署用到多種 Storefront 技術,例如 Storefront Reference Architecture (SFRA) 和 Composable Storefront,來提供單一購物體驗。
嵌入式 CDN (eCDN) 區域可將流量同時路由至 SFRA 和 Managed Runtime,讓您逐步部署出 Composable Storefront。
本指南說明如何使用 Commerce API CDN 區域將流量路由至 Managed Runtime。您還可以使用 Business Manager 將流量路由到 Managed Runtime。在 Business Manager 中設定 MRT 路由規則
在執行本指南的命令之前,請以實際值取代預留位置。預留位置的格式為:$PLACEHOLDER
在本指南中,我們使用帶有生產URL https://www.example.com的示例網店。
只有現有客戶才能存取此頁面上的某些連結。造訪 Salesforce Commerce Cloud GitHub 存放庫和存取,以瞭解有關如何存取 Commerce Cloud 存放庫的資訊。
Tip
sfcc.cdn-zones.rw 範圍的 Account Manager API 用戶端。alwaysUseHttps。Managed Runtime 僅支援 HTTPS 流量。redirect_uri 以納入該區域。藉由 createMrtRules 端點,您可以建立規則,將流量路由至 Managed Runtime 環境:
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules" \
2 --header "Authorization: Bearer $TOKEN" \
3 --header 'Content-Type: application/json' \
4 --data '{
5 "mrtHostname": "example-production.mobify-storefront.com",
6 "expressions": [
7 "http.host eq \"www.example.com\" and http.request.uri.path matches \"^/products\""
8 ]
9 }'讓我們檢驗一下要求本文中提供的資料。
mrtHostname 的值為 Managed Runtime 環境的網域,用於流量路由。它必須參照到裝載於 mobify-storefront.com 網域的 Managed Runtime 環境。如果提供的值已被現有的規則所使用,則要求會失敗。
Managed Runtime 是唯一受支援的路由目的地。
Note
expressions 的值是 Cloudflare 規則表達式的陣列,控制要將哪些要求路由至 Managed Runtime。對大多數實作而言,單一路由表達式已經足夠了。
除了所提供的表達式,也會使用下列預設的路由規則:
1(
2 http.request.uri.path matches "^/callback.*" or
3 http.request.uri.path matches "^/mobify.*" or
4 http.request.uri.path matches "^/worker\.js.*"
5)路由變更會立即套用,瀏覽至符合表達式的 URL 時,會傳回從 Managed Runtime 擷取的內容。
支援以下路由方案:
映射到單個 MRT 環境的單個主機名稱:
http.host eq \"www.example.com\" → example-production.mobify-storefront.com多個主機名映射到單個 MRT 環境:
http.host in {\"www.example.com\" \"prod.example.com\" \"us.example.com\"}→ example-production.mobify-storefront.com目前 不支援 以下路由方案:
表達式根據以下準則進行驗證:
http.host 必須恰好出現一次,並且後面必須跟著 eq OR in 運算子。有關使用範例,請參閱上文。http.hosthttp.request.uri.pathhttp.request.urihttp.cookie當您繼續分階段部署時,您可以將更多要求路由至 Managed Runtime。
若要修改路由表達式,請使用 getMrtRule 取得與您欲更新的表達式相關聯的規則集和規則的 ID。
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules" \
2--header "Authorization: Bearer $TOKEN"接下來,使用 updateMrtRule 更新表達式:
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules/$RULESET/rules/$RULE" \
2--request 'PATCH' \
3--header "Authorization: Bearer $TOKEN" \
4--header 'Content-Type: application/json' \
5--data '{
6 "expression": "http.host eq \"www.example.com\" and (http.request.uri.path matches \"^/products\" or http.request.uri.path matches \"^/categories\")"
7 }'若要向 現有 託管運行時環境添加更多路由規則,請使用 updateMrtRuleset 並提供 mrtHostname 和其他路由表達式:
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules" \
2 --request 'PATCH' \
3 --header "Authorization: Bearer $TOKEN" \
4 --header 'Content-Type: application/json' \
5 --data '{
6 "mrtHostname": "example-production.mobify-storefront.com",
7 "expressions": ["http.host eq \"www.example.com\" and http.request.uri.path matches \"^/home\""]
8 }'若要為 新的 託管運行時環境添加路由規則,請使用 createMrtRules 端點並提供新 mrtHostname 值:
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules" \
2--header "Authorization: Bearer $TOKEN" \
3--header 'Content-Type: application/json' \
4--data '{
5 "mrtHostname": "example-development.mobify-storefront.com",
6 "expressions": [
7 "http.host eq \"dev.example.com\" and http.request.uri.path matches \"^/products\""
8 ]
9 }'若要更新現有規則以路由到其他託管運行時環境,請使用 updateMrtRuleset 並提供 oldMrtHostname 要路由到的 和 (new): mrtHostname
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules" \
2 --request 'PATCH' \
3 --header "Authorization: Bearer $TOKEN" \
4 --header 'Content-Type: application/json' \
5 --data '{
6 "oldMrtHostname": "example-old.mobify-storefront.com",
7 "mrtHostname": "example-new.mobify-storefront.com"
8 }'如果您要切換到第三方 CDN,或者您不想再將特定路徑從 eCDN 路由到 MRT,您可以禁用路由。
若要禁用路由,請使用 getMrtRules 獲取要刪除的配置的 ID:
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules" \
2--header "Authorization: Bearer $TOKEN"然後,若要刪除Managed Runtime 路由規則,請使用 deleteMrtRule 並傳入 getMrtRules 傳回的適用 ID:
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules/$RULESET/rules/$RULE" \
2--request 'DELETE' \
3--header "Authorization: Bearer $TOKEN"如果要刪除所有託管運行時路由規則,請使用 deleteMrtRuleset:
1`curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/mrtrules/$RULESET" \`
2--request 'DELETE' \
3--header "Authorization: Bearer $TOKEN"當您完成分階段部署,或如果您要推出新網站,您可以選擇使用單一表達式,將一個區域的所有流量路由至 Managed Runtime:
1http.host eq \"www.example.com\"在 eCDN 不可用的環境中,請使用 composable-hybrid-dev-server 來模擬 eCDN 路由。