need
A client has multiple JS storefronts and wants to connect each to a different API endpoint, but by default all JS storefronts are bound to the same API.
current implementation
Unless the OCC base URL is explicitly configured, the 第一个
API endpoint in the Cloud Portal will be the one associated with each JS Storefront.
solution
Every JS Storefront application should explicitly define the OCC base URL using a meta tag in index.html, such as the code below:
<meta name="occ-backend-base-url" content="https://my-custom-backend-url:8080" />
Instead of hardcoding it in the Spartacus configuration using provideConfig(), developers can configure the base URL using a special HTML meta tag. This allows you to deploy to different environments using just one compiled JavaScript application, since you only need to modify the meta tags of the index.html file for each environment.
The value of backend.occ.baseUrl in provideConfig() in 优先于
the value in the meta tag, so if the client wants the base URL to be dynamically driven by the meta tag, please do not define it in provideConfig() baseUrl.
A common problem in real projects is that Spartacus accidentally sends requests to the API service over the public network rather than internally.
The following are normal requests:
https://api.<project-name>-<customer-name>-<environment-id>-public.model-t.cc.commerce.ondemand.com/occ/v2
The following are bad requests:
https://api.<customer-domain>.com/occ/v2
The reason for this error is that the value of occ-backend-base-url was incorrectly modified/customized due to misunderstanding.
The following is a wrong implementation:
<meta name="occ-backend-base-url" content=https://api.<customer-domain>.com/occ/v2 />
Correct implementation:
<meta name="occ-backend-base-url" content="OCC_BACKEND_BASE_URL_VALUE" />
Only with the correct placeholder OCC_BACKEND_BASE_URL_VALUE will this placeholder be properly replaced by the actual API endpoint in the API aspect when deploying to CCV2.
There are two ways to configure CORS for Spartacus.
Method 1: Local Properties Configuration
Change properties via hac, service configuration, or properties file referenced by manifest.json.
Method 2: Global CORS configuration
Configure in Backoffice:
The second configuration has higher priority. The logic is implemented in de.hybris.platform.core.cors.web.DefaultCorsConfigurationSource, the code is as follows .
The global CORS configuration is stored in the database within the CorsConfigurationProperty item. This is global and applies to all nodes connected to the cluster.
Properties in the database take precedence over local properties. If the same properties context and key are configured in both the database and properties file, the value is taken from the database.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。