www/apps/resources/app/deployment/storefront/vercel/page.mdx
import RewritesError from "../../../troubleshooting/_sections/storefront/rewrites.mdx" import { Prerequisites, DetailsList } from "docs-ui"
export const metadata = {
title: Deploy Next.js Starter Storefront to Vercel,
}
In this guide, you’ll learn how to deploy the Next.js Starter Storefront to Vercel.
<Note title="Deploy with Cloud" type="success">Cloud supports deploying storefronts alongside your Medusa application with zero-configuration.
Cloud is our managed services offering that makes deploying and operating Medusa applications possible without having to worry about configuring, scaling, and maintaining infrastructure. Cloud hosts your server, Admin dashboard, storefront, database, and Redis instance.
With Cloud, you maintain full customization control as you deploy your own modules and customizations directly from GitHub:
Sign up and learn more about Cloud.
</Note><Prerequisites items={[ { text: "Storefront codebase hosted in a GitHub repository.", link: "../../../nextjs-starter/page.mdx" }, { text: "Deployed Medusa application with at least one region.", link: "../../page.mdx#medusa-application" }, ]} />
On your Vercel dashboard:
This opens a form to configure your project.
In the Configure Project form, choose Next.js for the Framework Preset field. This sets for you the build and install scripts, and the output directory
<Details summaryContent="Expected Values">build script:npm run build
install script:npm install
.nextThen, expand the Environment Variables section and add the following variables:
MEDUSA_BACKEND_URL= # URL of Medusa application
NEXT_PUBLIC_DEFAULT_REGION=us # or a different region that you prefer
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY= # publishable API key of the storefront's sales channel
REVALIDATE_SECRET=supersecret # TODO generate random string
Where:
MEDUSA_BACKEND_URL is the URL of your deployed Medusa applicationNEXT_PUBLIC_DEFAULT_REGION is the country code of a region to be used by default, if the customer hasn’t selected a region.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY is the publishable API key of the storefront. You can create one or find the default one in the Medusa Admin dashboard.REVALIDATE_SECRET is a random string for Next.js revalidation.Make sure to add other relevant environment variables. For example, if you’re using the Stripe Payment Module Provider in the Medusa application, add the NEXT_PUBLIC_STRIPE_KEY environment variable.
Click the Deploy button when you’re done. The deployment will take a few minutes.
Once the deployment is done, there’s still more work to do before you can use the storefront. Click on the Continue to Dashboard button to go to the project’s dashboard.
Vercel generates a random domain name for your project. You can use it or set a custom domain name.
<Note title="Tip">Find your generated domain name at Settings → Domains in your project’s dashboard.
</Note>Once you have your domain name:
NEXT_PUBLIC_BASE_URL=https://nextjs-storefront...
Set the value to the storefront’s URL.
You must also set the STORE_CORS environment variable in your Medusa application to the storefront’s URL:
STORE_CORS=https://nextjs-storefront...
If you have multiple storefront URLs, separate them by commas in STORE_CORS
And add the URL to AUTH_CORS's value:
AUTH_CORS=<OTHER_URLS>,https://nextjs-storefront...
Where <OTHER_URLS> are other storefront or admin URLs added previously to AUTH_CORS.
Once the environment variables changes are deployed in the Medusa application, do the following to redeploy the storefront:
Once the redeployment is done, test out the storefront by going to its URL. Try to browse the products or place an order to ensure everything is working as expected.
If you’re running into issues in your storefront, find the logs in your Vercel project’s dashboard under the Logs tab.
<DetailsList sections={[ { title: "Login Page Error", content: <RewritesError /> } ]} />