For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts. Only in a local environment does the REST API simulate CORS enabled.
If you simply want to enable but don’t want to add any code snippets, you can simply install CoCart CORS Support plugin.
Enable CORS
Single Domain Access
Access via a single domain access should be enough.Multiple Domain Access
You can support many domains access using thecocart_allowed_http_origins
filter.
Do not use
cocart_allow_origin
filter at the same time as it will break.Parameter | Type | Description |
---|---|---|
$allowed_origins | string[] | Array of default allowed HTTP origins. |
Allowed Ports
You can change the list of ports considered safe for accessing the REST API. The ports can also be restricted by the host and/or requested URL.Default Ports: 80, 443, 8080
Parameter | Type | Description |
---|---|---|
$ports | int[] | Array of integers for valid ports. |
$host | string | Host name of the requested URL. |
$url | string | Requested URL. |