docs/developer/storefront/nextjs/deployment.mdx
At minimum, set SPREE_API_URL and SPREE_PUBLISHABLE_KEY in your hosting platform's dashboard or .env file. See Environment Variables for the full reference — analytics, error tracking, wholesale, emails, and SEO.
npm run build
npm start
The build output is a standalone Next.js application. The npm start command starts the production server.
Vercel is the recommended deployment platform for Next.js applications.
Push your code to GitHub
Go to vercel.com/new and import your repository
Add environment variables:
SPREE_API_URL and SPREE_PUBLISHABLE_KEY (required)SPREE_WEBHOOK_SECRET, RESEND_API_KEY, EMAIL_FROM — for transactional emailsGTM_ID — optional, Google Tag ManagerSENTRY_DSN, SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN — optional, error tracking with readable stack tracesSee the Environment Variables reference for the full list.
Click Deploy
Vercel automatically detects the Next.js framework and configures the build settings.
npm i -g vercel
vercel
Every pull request gets a unique preview URL, making it easy to test storefront changes before merging. Add your Spree API environment variables to the Vercel project settings so previews connect to your staging API.
A multi-stage Dockerfile ships at the repo root. It uses Next.js standalone output to produce a small (~240 MB) image on node:22-alpine, runs as a non-root user, and exposes port 3001.
Build and run:
docker build \
--build-arg SPREE_API_URL=https://your-spree.example.com \
--build-arg SPREE_PUBLISHABLE_KEY=your_publishable_key \
-t spree-storefront .
docker run -p 3001:3001 --env-file .env.local spree-storefront
SENTRY_AUTH_TOKEN is passed via a BuildKit secret so it never lands in image layers or the build cache. The other Sentry vars are regular build args:
SENTRY_AUTH_TOKEN=... docker build \
--build-arg SPREE_API_URL=... \
--build-arg SPREE_PUBLISHABLE_KEY=... \
--build-arg SENTRY_DSN=... \
--build-arg SENTRY_ORG=... \
--build-arg SENTRY_PROJECT=... \
--secret id=sentry_auth_token,env=SENTRY_AUTH_TOKEN \
-t spree-storefront .
On Docker Desktop (macOS/Windows), reach the host's Spree via host.docker.internal:
docker build \
--add-host=host.docker.internal:host-gateway \
--build-arg SPREE_API_URL=http://host.docker.internal:3000 \
--build-arg SPREE_PUBLISHABLE_KEY=your_publishable_key \
-t spree-storefront .
docker run -p 3001:3001 \
--add-host=host.docker.internal:host-gateway \
--env-file .env.local \
spree-storefront
For any platform that supports Node.js (Render, Railway, Fly.io, AWS, etc.):
npm ci
npm run build
npm start
The server listens on port 3001. Set the PORT environment variable to change it.
name: Deploy Storefront
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run build
# Add your deployment step here
# Example for Vercel:
# - uses: amondnet/vercel-action@v25
# with:
# vercel-token: ${{ secrets.VERCEL_TOKEN }}
# vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
# vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
# vercel-args: --prod
Before going to production, verify:
localhost)SENTRY_DSN)GTM_ID)secure: true for cookies in production (NODE_ENV=production)