# Deploy to Azure with Static Web Apps Learn how to deploy your customization to [Azure](https://azure.microsoft.com/en-us/services/app-service/static/#overview) with Static Web Apps. ## Prerequisites Before you get started, you need to have: - An [Azure](https://azure.microsoft.com/en-us/free/) account. - A Project - A Merchant Center account, or an [Identity account](/docs/identity/overview.md) - A customization configured in the Merchant Center: - For Custom Applications, see [Managing Custom Applications](/merchant-center/managing-custom-applications.md). - For Custom Views, see [Managing Custom Views](/merchant-center/managing-custom-views.md). ## Configuration ### Add the customization identifier and URL Depending on the customization type, you'll need to specify either the Custom Application ID or the Custom View ID that was provided to you when you added the customization in the Merchant Center. You'll also need to specify the production URL from your Azure project. You can keep the standard Azure Static Web Apps URL `https://.1.azurestaticapps.net` or provide your custom domain. For Custom Applications, make the following changes to the [Custom Application config](/merchant-center-customizations/tooling-and-configuration/custom-application-config.md): - Add the Custom Application ID to [`env.production.applicationId`](/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#envproductionapplicationid). - Add the production URL from your Azure project to [`env.production.url`](/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#envproductionurl). ```json title="custom-application-config.json" { "env": { "production": { "applicationId": "ckvtahxl90097sys6har1e6n3", "url": "https://.1.azurestaticapps.net" } } } ``` For Custom Views, make the following changes to the [Custom View config](/merchant-center-customizations/tooling-and-configuration/custom-view-config.md): - Add the Custom View ID to [`env.production.customViewId`](/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#envproductioncustomviewid). - Add the production URL from your Azure project to [`env.production.url`](/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#envproductionurl). ```js title="custom-view-config.mjs" { "env": { "production": { "customViewId": "ckvtahxl90097sys6har1e6n3", "url": "https://.1.azurestaticapps.net" } } } ``` ### Use environment variables To avoid hardcoding values (such as the customization identifier or the Project key), you can use variable placeholders in your [Custom Application config](/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#use-variable-placeholders) or [Custom View config](/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#use-variable-placeholders). Example of environment variables with Custom Applications: ```json title="custom-application-config.json" highlightLines="4" { "env": { "production": { "applicationId": "${env:APPLICATION_ID}", "url": "https://.1.azurestaticapps.net" } } } ``` Example of environment variables with Custom Views: ```js title="custom-view-config.mjs" highlightLines="4" const config = { env: { production: { customViewId: '${env:CUSTOM_VIEW_ID}', url: 'https://.1.azurestaticapps.net', }, }, // ... }; ``` ## Connect Azure with GitHub Actions The easiest way to deploy to Azure is to use [Static Web Apps](https://azure.microsoft.com/en-us/services/app-service/static/#overview) deployment service. This service enables first-class GitHub integration. Follow the steps in the [Azure Static Web App creator](https://portal.azure.com/#create/Microsoft.StaticApp) 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. ### Configure 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` If your customization config [requires environment variables](/merchant-center-customizations/deployment/azure-static-web-apps.md#use-environment-variables), make sure to provide them in the [GitHub Action workflow file](https://docs.microsoft.com/en-us/azure/static-web-apps/build-configuration?tabs=github-actions#environment-variables). You can define the environment variables either as plain text or using [GitHub encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets). See example below for defining environment variables for the GitHub action: ```yaml title="deployment.yml" highlightLines="9-10" - name: Build And Deploy uses: Azure/static-web-apps-deploy@v1 with: action: 'upload' app_location: '/' api_location: '' output_location: 'public' env: APPLICATION_ID: ${{ secrets.APPLICATION_ID }} CLOUD_IDENTIFIER: gcp-eu ``` ### Configure rewrite rules A customization is a Single-Page Application that uses client-side routing. Therefore, we need to [instruct Azure](https://learn.microsoft.com/en-us/azure/static-web-apps/configuration#define-routes) 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: ```json title="staticwebapp.config.json" { "responseOverrides": { "404": { "rewrite": "/index.html", "statusCode": 200 } } } ``` ## Test your deployment Install your customization in the Merchant Center to access it within your Projects: - For Custom Applications, see [Managing Custom Applications](/merchant-center/managing-custom-applications.md). You can also use [deployment previews](/merchant-center-customizations/concepts/deployment-previews.md) to test the application before releasing it to the production environment. - For Custom Views, see [Managing Custom Views](/merchant-center/managing-custom-views.md). ## Related pages - [Area overview page with navigation](/merchant-center-customizations.md) - [Previous page: Deploy to AWS with S3 and CloudFront](/merchant-center-customizations/deployment/aws-s3-cloudfront.md) - [Next page: Deploy to Azure with Blob Storage](/merchant-center-customizations/deployment/azure-blob-storage.md) - [Search documentation and API specs](/search.md)