This is the early access documentation preview for Custom Views. This documentation might not be in sync with our official documentation.
Deploying to Azure with Static Web Apps
This deployment example refers to Azure Static Web Apps.
Prerequisites
Before you get started, you need to have:
- An Azure account.
- A commercetools account and a Project.
- A Custom Application configured in the Merchant Center.
Configuration
In your Custom Application config, provide the Custom Application ID you got when you configured the Custom Application in the Merchant Center.
Moreover, you need to provide the production URL from your Azure project. You can keep the standard Azure Static Web Apps URL https://<project>.1.azurestaticapps.net
or provide your custom domain.
{"env": {"production": {"applicationId": "ckvtahxl90097sys6har1e6n3","url": "https://<project>.1.azurestaticapps.net"}}}
Using environment variables
In case you want to avoid hardcoding certain values, for example the Application ID, or the Project key, you can use variable placeholders in your Custom Application config.
{"env": {"production": {"applicationId": "${env:APPLICATION_ID}","url": "https://<project>.1.azurestaticapps.net"}}}
Connect Azure with GitHub Actions
The easiest way to deploy to Azure is to use Static Web Apps deployment service. This service enables first-class GitHub integration.
Follow the steps in the Azure Static Web App creator to create a new project and select GitHub
as the deployment source.
Make sure to grant Azure access to your repository in the following step.
Configuring build settings
In the Static Web App setup process you need to configure the following things:
- Select your organization, repository and branch.
- In the Build details section select
Custom
as the build preset. - Provide the following build settings:
- App location:
/
- Output location:
public
- App location:
If your Custom Application config requires environment variables, make sure to provide them in the GitHub Action workflow file. You can define the environment variables either as plain text or using GitHub encrypted secrets.
See example below for defining environment variables for the GitHub action:
- name: Build And Deployuses: Azure/static-web-apps-deploy@v1with:action: 'upload'app_location: '/'api_location: ''output_location: 'public'env:APPLICATION_ID: ${{ secrets.APPLICATION_ID }}CLOUD_IDENTIFIER: gcp-eu
Configuring rewrite rules
A Custom Application is a Single-Page Application that uses client-side routing. Therefore, we need to instruct Azure to rewrite all requests to serve the index.html
.
For this purpose, create staticwebapp.config.json
file in the root directory of your project with the following content:
{"responseOverrides": {"404": {"rewrite": "/index.html","statusCode": 200}}}
Test your deployment
In the Merchant Center you can now follow the steps to install the Custom Application and access it in your Projects.
The Custom Application won't render if you try to access it directly via the deployment URL, as it needs to be served within the Merchant Center Proxy Router.
Therefore, Preview deployments are not really useful. If you are interested in this functionality, let us know and open a support issue.