docs/developer/storefront/nextjs/deployment.mdx
Set these variables in your hosting platform's dashboard or .env file.
| Variable | Description |
|---|---|
SPREE_API_URL | Your Spree API endpoint (e.g., https://api.mystore.com) |
SPREE_PUBLISHABLE_KEY | Publishable API key from your Spree admin |
| Variable | Description | Default |
|---|---|---|
GTM_ID | Google Tag Manager container ID | (disabled) |
SENTRY_DSN | Sentry DSN for error tracking | (disabled) |
SENTRY_ORG | Sentry organization slug | (none) |
SENTRY_PROJECT | Sentry project slug | (none) |
SENTRY_AUTH_TOKEN | Sentry auth token (for source maps in CI) | (none) |
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.
SPREE_API_URL, SPREE_PUBLISHABLE_KEY)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.
Create a Dockerfile in your project root:
FROM node:20-alpine AS base
FROM base AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --production=false
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
const nextConfig = {
output: 'standalone',
}
Build and run:
docker build -t spree-storefront .
docker run -p 3000:3000 \
-e SPREE_API_URL=https://api.mystore.com \
-e SPREE_PUBLISHABLE_KEY=your_key \
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 3000 by default. 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)