多重網站

使用 Retail React App 範本建立 PWA Kit 專案後,根據預設,會得到一個地區設定和一個網站。然而,也可以擴展為使用單個程式碼庫來執行多個網站。

網站設定 

config/sites.js 檔案包含您在 Business Manager 上設定好的網站定義。以下範例將顯示 RefArchRefArchGlobal 網站的設定:

1// /config/sites.js
2
3module.exports = [
4  {
5    id: "RefArch",
6    l10n: {
7      supportedCurrencies: ["USD"],
8      defaultCurrency: "USD",
9      defaultLocale: "en-US",
10      supportedLocales: [
11        {
12          id: "en-US",
13          alias: "us",
14          preferredCurrency: "USD",
15        },
16        {
17          id: "en-CA",
18          preferredCurrency: "USD",
19        },
20      ],
21    },
22  },
23  {
24    id: "RefArchGlobal",
25    l10n: {
26      supportedCurrencies: ["GBP", "EUR", "JPY"],
27      defaultCurrency: "GBP",
28      supportedLocales: [
29        {
30          id: "de-DE",
31          alias: "de",
32          preferredCurrency: "EUR",
33        },
34        {
35          id: "en-GB",
36          preferredCurrency: "GBP",
37        },
38        {
39          id: "ja-JP",
40          preferredCurrency: "JPY",
41        },
42      ],
43      defaultLocale: "en-GB",
44    },
45  },
46];

預設網站和別名 

/config/default.js 檔案中,您可以設定預設網站,也可以選擇將網站 ID 對應至別名。若此網站沒有定義別名,則 URL 中將使用 ID。以下範例將預設網站設為 RefArchGlobal,並為其定義三個別名。

1// /config/default.js
2
3defaultSite: 'RefArchGlobal',
4siteAliases: {
5    RefArch: 'us',
6    RefArchGlobal: 'global',
7    NTOManaged: 'nto'
8},

若您在 /config/default.js 檔案中將 url.showDefault 設定為 true,則預設地區設定和網站將顯示在您的應用程式 URL 中。除了網站別名外,您也可以在 sites.js 檔案中為地區設定配置別名。若您為地區設定配置了別名,則 URL 將會顯示別名,而非地區設定 ID。

應用程式 URL 是使用標準的網站和地區設定 ID 而建構的,即便使用別名也仍然是有效的 URL。

Note

多網域部署 

透過特定於環境的設定檔,您可以管理在 Business Manager 中定義的多個 B2C 網站,並使用多個 Managed Runtime 環境將它們部署在不同的網域中。

舉例來說,您的網站可從 customer.cacustomer.uk 存取,也能從 customer-a.comcustomer-b.ca 存取。您也可以進一步自訂 URL 模式。舉例來說,您的 URL 可以格式化為 customer-1.com/uscustomer-2.com/?locale=en_US

為了與多個網域一起運作,您可以使用不同的 Managed Runtime 環境來部署套件,每一個都可為不同網域進行設定。只要為每個 Managed Runtime 環境建立個別的設定檔,就能進行設定對應。

例如,若要將 customer-1.com 部署至 env-customer-1 環境,並將 customer-2.com 部署至 env-customer-2 環境,您必須建立以下檔案來代替 config/default.js

  • config/env-customer-1.js
  • config/env-customer-2.js

如需進一步瞭解特定於環境的設定,請參閱設定檔指南。

也請參閱