# Deploy to Surge Learn how to deploy your customization to [Surge](https://surge.sh/). ## Prerequisites Before you get started, you need to have: - A [Surge](https://surge.sh) account, using the `surge` CLI. - A Project - A Merchant Center account, or an [Identity account](https://docs.commercetools.com/docs/identity/overview.md) - A customization configured in the Merchant Center: - For Custom Applications, see [Managing Custom Applications](https://docs.commercetools.com/merchant-center/managing-custom-applications.md). - For Custom Views, see [Managing Custom Views](https://docs.commercetools.com/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 Surge project. You can keep the standard Surge URL `https://.surge.sh` or provide your custom domain. For Custom Applications, make the following changes to the [Custom Application config](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md): - Add the Custom Application ID to [`env.production.applicationId`](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#envproductionapplicationid). - Add the production URL from your Surge project to [`env.production.url`](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#envproductionurl). ```json title="custom-application-config.json" { "env": { "production": { "applicationId": "ckvtahxl90097sys6har1e6n3", "url": "https://.surge.sh" } } } ``` For Custom Views, make the following changes to the [Custom View config](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-view-config.md): - Add the Custom View ID to [`env.production.customViewId`](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#envproductioncustomviewid). - Add the production URL of your Surge project to [`env.production.url`](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#envproductionurl). ```js title="custom-view-config.mjs" const config = { env: { production: { customViewId: 'ckvtahxl90097sys6har1e6n3', url: 'https://.surge.sh', }, }, // ... }; ``` ### 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](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#use-variable-placeholders) or [Custom View config](https://docs.commercetools.com/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://.surge.sh" } } } ``` 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://.surge.sh', }, }, // ... }; ``` ## Production bundles The main command to create the production bundles is `mc-scripts build`. The output folder is `public`, which is what is going to be uploaded to Surge. For more information, see [Going to production](https://docs.commercetools.com/merchant-center-customizations/development/going-to-production.md). To properly [support client-side routing](https://surge.sh/help/adding-a-200-page-for-client-side-routing), you need to rename the `index.html` file to `200.html` before uploading the static files. ## Deploy to Surge Use the [Surge CLI](https://www.npmjs.com/package/surge) to upload the static files. ```console surge public https://.surge.sh ``` ## Test your deployment Install your customization in the Merchant Center to access it within your Projects: - For Custom Applications, see [Managing Custom Applications](https://docs.commercetools.com/merchant-center/managing-custom-applications.md). You can also use [deployment previews](https://docs.commercetools.com/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](https://docs.commercetools.com/merchant-center/managing-custom-views.md). ## Related pages - [Section overview page](https://docs.commercetools.com/merchant-center-customizations.md) - [Previous page: Deploy to Azure with Blob Storage](https://docs.commercetools.com/merchant-center-customizations/deployment/azure-blob-storage.md) - [Next page: Deploy to Cloudflare Pages](https://docs.commercetools.com/merchant-center-customizations/deployment/cloudflare.md)