Deploy Next.js to Quant
Next.js is a popular React framework with excellent support for both static generation and server-side rendering. This guide covers deploying Next.js applications to Quant.
Deployment options
Section titled “Deployment options”| Approach | Best for | Platform |
|---|---|---|
| Static Export | Marketing sites, blogs, documentation | Quant Static |
| Server-side Rendering | Dynamic apps, authenticated content, API routes | Quant Cloud |
Static Export
Section titled “Static Export”For sites that can be fully pre-rendered, static export gives you the fastest performance with global CDN delivery.
Step 1: Configure Next.js for static export
Section titled “Step 1: Configure Next.js for static export”Update your next.config.js:
/** @type {import('next').NextConfig} */const nextConfig = { output: 'export', // Optional: Add trailing slashes trailingSlash: true, // Optional: Disable image optimisation (not supported in static export) images: { unoptimized: true, },};
module.exports = nextConfig;Step 2: Build and export
Section titled “Step 2: Build and export”npm run buildThis creates an out/ directory with your static site.
Step 3: Deploy with CLI
Section titled “Step 3: Deploy with CLI”npm install -g @quantcdn/quant-cli
# Initialisequant init# Set directory to: out
# Deployquant deployStep 4: GitHub Actions workflow
Section titled “Step 4: GitHub Actions workflow”Create .github/workflows/deploy.yml:
name: Deploy Next.js to Quant
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'
- name: Install dependencies run: npm ci
- name: Restore revision log uses: actions/cache@v5 with: path: .quant-revision key: quant-revision-${{ github.ref }}-${{ github.run_id }} restore-keys: | quant-revision-${{ github.ref }}-
- name: Build Next.js run: npm run build
- name: Deploy to Quant uses: quantcdn/deploy-action@v6 with: customer: ${{ secrets.QUANT_CUSTOMER }} project: ${{ secrets.QUANT_PROJECT }} token: ${{ secrets.QUANT_TOKEN }} dir: out revision-log: .quant-revision skip-purge: true
- name: Purge cache uses: quantcdn/purge-action@v6 with: customer: ${{ secrets.QUANT_CUSTOMER }} project: ${{ secrets.QUANT_PROJECT }} token: ${{ secrets.QUANT_TOKEN }} url_pattern: "/*"Static export limitations
Section titled “Static export limitations”Static export doesn’t support:
- Server Components that fetch data at request time
- API Routes
- Middleware
- Draft Mode
- Incremental Static Regeneration (ISR)
If you need these features, use Quant Cloud for server-side rendering.
Server-side Rendering with Quant Cloud
Section titled “Server-side Rendering with Quant Cloud”For full Next.js functionality including API routes, server components, and dynamic rendering, deploy to Quant Cloud.
Step 1: Configure Next.js
Section titled “Step 1: Configure Next.js”For App Router (recommended):
/** @type {import('next').NextConfig} */const nextConfig = { // Use standalone output for containerised deployment output: 'standalone',};
module.exports = nextConfig;Step 2: Create a Dockerfile
Section titled “Step 2: Create a Dockerfile”Create a Dockerfile in your project root:
FROM node:20-alpine AS base
# Install dependencies only when neededFROM base AS depsRUN apk add --no-cache libc6-compatWORKDIR /app
COPY package.json package-lock.json* ./RUN npm ci
# Rebuild the source code only when neededFROM base AS builderWORKDIR /appCOPY --from=deps /app/node_modules ./node_modulesCOPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# Production imageFROM base AS runnerWORKDIR /app
ENV NODE_ENV=productionENV NEXT_TELEMETRY_DISABLED=1ENV PORT=3000ENV HOSTNAME="0.0.0.0"
RUN addgroup --system --gid 1001 nodejsRUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./publicCOPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]Step 3: Create a Quant Cloud application
Section titled “Step 3: Create a Quant Cloud application”- Go to the Quant Dashboard
- Navigate to Cloud Applications → New Application
- Configure your application and environment
Step 4: Deploy with GitHub Actions
Section titled “Step 4: Deploy with GitHub Actions”Create .github/workflows/deploy-cloud.yml:
name: Deploy Next.js to Quant Cloud
on: push: branches: [main]
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Initialise Quant Cloud uses: quantcdn/quant-cloud-init-action@v1 id: init with: quant_organization: ${{ secrets.QUANT_ORGANIZATION }} quant_api_key: ${{ secrets.QUANT_API_KEY }}
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Build and push image uses: docker/build-push-action@v5 with: context: . platforms: linux/arm64 push: true tags: ${{ steps.init.outputs.stripped_endpoint }}/${{ secrets.QUANT_ORGANIZATION }}/my-nextjs-app:web${{ steps.init.outputs.image_suffix }} cache-from: type=gha cache-to: type=gha,mode=max
- name: Deploy environment uses: quantcdn/quant-cloud-environment-action@v1 with: quant_organization: ${{ secrets.QUANT_ORGANIZATION }} quant_api_key: ${{ secrets.QUANT_API_KEY }} application: my-nextjs-app environment: production operation: updateEnvironment variables
Section titled “Environment variables”Build-time variables
Section titled “Build-time variables”For static export, set environment variables in your CI workflow:
- name: Build Next.js run: npm run build env: NEXT_PUBLIC_API_URL: https://api.example.comRuntime variables (Quant Cloud)
Section titled “Runtime variables (Quant Cloud)”Configure in the dashboard under Environment Variables, or use the GitHub Action:
- name: Set environment variables uses: quantcdn/quant-cloud-environment-var-action@v1 with: quant_organization: ${{ secrets.QUANT_ORGANIZATION }} quant_api_key: ${{ secrets.QUANT_API_KEY }} application: my-nextjs-app environment: production variables: | DATABASE_URL=${{ secrets.DATABASE_URL }} API_SECRET=${{ secrets.API_SECRET }}Hybrid approach
Section titled “Hybrid approach”For the best of both worlds, you can:
- Static pages → Deploy to Quant Static for fastest delivery
- Dynamic routes → Deploy to Quant Cloud
- Use Page Rules → Route traffic appropriately
Example: Serve marketing pages statically, route /app/* to your Cloud instance.
App Router vs Pages Router
Section titled “App Router vs Pages Router”Both routers work with Quant:
| Router | Static Export | Quant Cloud |
|---|---|---|
| App Router | ✅ Full support | ✅ Full support |
| Pages Router | ✅ Full support | ✅ Full support |
For new projects, the App Router is recommended for its improved features and performance.
Performance tips
Section titled “Performance tips”- Use static generation where possible — Pre-render pages at build time for best performance
- Enable image optimisation — In Quant dashboard settings for static exports
- Leverage ISR on Quant Cloud — Incremental Static Regeneration works with server deployment
- Cache API responses — Use appropriate cache headers for API routes
Troubleshooting
Section titled “Troubleshooting””Image Optimization API is required” error
Section titled “”Image Optimization API is required” error”For static export, disable the Image Optimization API:
module.exports = { output: 'export', images: { unoptimized: true, },};Alternatively, use Quant’s built-in image optimisation by enabling it in the dashboard.
Dynamic routes returning 404
Section titled “Dynamic routes returning 404”For static export, ensure all dynamic routes are generated at build time:
export async function generateStaticParams() { const posts = await getPosts(); return posts.map((post) => ({ slug: post.slug }));}API routes not working
Section titled “API routes not working”API routes require server-side rendering. For static export, move API logic to:
- External API services
- Serverless functions
- Quant Cloud deployment
Container health check failing
Section titled “Container health check failing”Ensure your application:
- Listens on the correct port (default: 3000)
- Responds to health check requests
- Binds to
0.0.0.0, notlocalhost
module.exports = { output: 'standalone', experimental: { // Ensure proper hostname binding },};Next steps
Section titled “Next steps”- Add a custom domain — Point your domain to Quant
- Configure WAF — Protect your application
- Set up Quant Cloud — Full container hosting documentation