www/apps/cloud/app/storefront/page.mdx
import { CodeTab, CodeTabs } from "docs-ui"
export const metadata = {
title: Storefront Deployment on Cloud,
}
In this guide, learn how to deploy your storefront with your Medusa application on Cloud.
Medusa allows you to deploy your storefront alongside your Medusa application on Cloud, enabling you to host and manage both backend and frontend in a single platform.
To deploy a storefront with your Medusa application on Cloud, you need a monorepo structure where both the Medusa application and storefront code are in the same repository. Medusa then builds and deploys both the backend and frontend.
Similar to the Medusa backend, Medusa deploys a storefront for every long-lived and preview environment, based on your plan's limits. This allows you to test and preview changes in isolation.
Medusa also automatically configures the necessary settings for each environment, such as URLs, API keys, and Cross-Origin Resource Sharing (CORS) settings, to ensure seamless connectivity between the storefront and Medusa application.
To deploy a storefront with your Medusa application on Cloud, you can either:
Unless you create a new project from a starter, you'll need to set up the monorepo structure. Learn how to create the monorepo in the Prerequisites guide.
Cloud's storefront hosting includes the following features:
Storefront deployment is included in your organization's plan at no additional cost, subject to usage limits.
Exceeding these limits may incur Flex Usage charges.
Cloud currently supports deploying storefronts built with the following frameworks:
If you're using a different framework for your storefront, contact support to request it.
By default, storefronts are deployed at the medusajs.site subdomain. The domain prefix is the same as the Medusa application's subdomain. For example, if your Medusa application is at my-store.medusajs.app, your storefront will be at my-store.medusajs.site.
You can also set up a custom domain for your storefront to use a branded URL. For detailed instructions on setting up and managing custom domains for your storefront, refer to the Custom Domains guide.
The following section covers considerations to keep in mind when deploying your storefront to Cloud.
When building your storefront before deployment on Cloud, Medusa runs the build command specific to your storefront framework. For example, if you're using Next.js, Medusa runs next build to build your storefront.
So, if you perform any custom commands or manipulation during the build process, Medusa will not run them.
When deploying your storefront to Cloud, you don't need to add any specific configurations for deployment. For example, you don't need to specify the hosting provider with a Vite plugin in Tanstack Start.
Medusa automatically injects the necessary configurations during the deployment process to ensure your storefront is correctly set up on Cloud.
When deploying your storefront to Cloud, Medusa automatically injects the following environment variables into your storefront's build and runtime process:
<CodeTabs group="storefront-framework"> <CodeTab label="Next.js" value="nextjs">NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY # Your Medusa application's publishable key
NEXT_PUBLIC_MEDUSA_BACKEND_URL # Your Medusa backend's URL
NEXT_PUBLIC_BASE_URL # Your storefront's URL
MEDUSA_BACKEND_URL # Your Medusa backend's URL
BASE_URL # Your storefront's URL
VITE_MEDUSA_PUBLISHABLE_KEY # Your Medusa application's publishable key
VITE_MEDUSA_BACKEND_URL # Your Medusa backend's URL
VITE_BASE_URL # Your storefront's URL
MEDUSA_BACKEND_URL # Your Medusa backend's URL
BASE_URL # Your storefront's URL
So, make sure to use these environment variables in your storefront to connect it to your Medusa backend.
You can also add custom environment variables to your storefront either during the project creation process on Cloud or later via the project settings.