Deployment
This guide covers deploying your Next.js TS Tailwind Supabase Starter application to production environments.
Deployment Options
The starter template supports various deployment options:
- Vercel (recommended for Next.js applications)
- Netlify
- AWS Amplify
- Docker + Self-hosted
Environment Setup
Before deploying, ensure you have set up the following environment variables in your deployment environment:
# Next.js
NEXT_PUBLIC_APP_URL=https://your-app-domain.com
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
Deploying to Vercel
Vercel is the platform created by the team behind Next.js and offers the most seamless deployment experience.
Steps:
-
Push your code to a Git repository (GitHub, GitLab, BitBucket)
-
Connect your repository to Vercel:
- Create a Vercel account at vercel.com
- Click "New Project" and import your repository
- Select "Next.js" as the framework preset
-
Configure environment variables:
- Add the environment variables mentioned above
- You can set different values for production, preview, and development environments
-
Deploy:
- Click "Deploy" to trigger the initial deployment
- Vercel will automatically build and deploy your application
-
Set up automatic deployments:
- By default, Vercel deploys automatically on every push to the main branch
- You can customize this behavior in the project settings
Deploying to Netlify
Netlify is another popular option for deploying Next.js applications.
Steps:
-
Push your code to a Git repository
-
Connect your repository to Netlify:
- Create a Netlify account at netlify.com
- Click "New site from Git" and import your repository
-
Configure build settings:
- Build command:
npm run build
- Publish directory:
.next
- Build command:
-
Configure environment variables:
- Add the environment variables in the site settings
-
Deploy:
- Click "Deploy site" to trigger the initial deployment
-
Add the Netlify Next.js plugin:
- Install the plugin with
npm install -D @netlify/plugin-nextjs
- Add a
netlify.toml
file to your project root:
- Install the plugin with
[[plugins]]
package = "@netlify/plugin-nextjs"
Deploying with Docker
For self-hosted deployments, you can use Docker.
Creating a Dockerfile
# Dockerfile
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Production image, copy all the files and run next
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 /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
Configuring Next.js for Docker
Update your next.config.js
to enable standalone mode:
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
// ... other config
};
module.exports = nextConfig;
Docker Compose (Optional)
For local development with Docker:
# docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
environment:
- NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
- NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
Supabase Configuration for Production
When deploying to production, ensure your Supabase project is properly configured:
-
Update authentication settings:
- Set the Site URL to your production domain
- Configure redirect URLs for authentication
- Set up email templates for authentication emails
-
Update Row Level Security policies:
- Review and test RLS policies before deploying to production
- Ensure all tables have appropriate RLS policies
-
Database backups:
- Set up regular database backups
- Consider implementing point-in-time recovery
CI/CD Pipeline
The starter template can be integrated with popular CI/CD tools:
GitHub Actions Example
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Deploy to Vercel
uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: '--prod'
Post-Deployment Checks
After deploying, perform these checks:
- Test authentication flows in the production environment
- Verify database connections are working correctly
- Check for any CORS issues with Supabase
- Test protected routes to ensure they're properly secured
- Verify environment variables are correctly set
Performance Optimization
For production deployments, consider these optimizations:
- Enable Edge Runtime for API routes where possible
- Implement ISR (Incremental Static Regeneration) for frequently accessed pages
- Configure caching headers for static assets
- Optimize images using Next.js Image optimization
- Configure Content Security Policy headers
Monitoring and Analytics
Consider adding:
- Error tracking (Sentry, LogRocket)
- Analytics (Google Analytics, Plausible, Fathom)
- Performance monitoring (Vercel Analytics)
- Uptime monitoring (UptimeRobot, Pingdom)
Next Steps
- Check out the Version Reference for recommended versions of all dependencies
- Read the Contributing guide for information on contributing to the project