Implementation Patterns
Deployment
This page covers building for production, configuring hosting platforms, ISR revalidation, robots.txt, sitemaps, and a pre-deployment checklist.
Building for Production
Run the standard Next.js build:
npm run build
During the build, Next.js will:
- Call
generateStaticParams()to get all page paths across all locales - Pre-render every page by fetching content from the Brease API
- Fetch and configure redirects from
next.config.ts - Generate static HTML, CSS, and JS bundles
Then start the production server:
npm start
Build requires API access
The build process fetches all content from Brease. Make sure BREASE_TOKEN and BREASE_ENV are available as environment variables during the build step on your hosting platform.
Incremental Static Regeneration (ISR)
Pages are revalidated on a timer controlled by the BREASE_REVALIDATION_TIME environment variable (in seconds). The default is 30.
| Value | Behavior |
|---|---|
30 (default) | Pages revalidate every 30 seconds after first request |
60 | Revalidate every minute |
0 | Disable time-based revalidation (on-demand only) |
false | Disable revalidation entirely (fully static) |
When a page is requested after the revalidation window, Next.js serves the cached version immediately and regenerates the page in the background. The next request receives the updated content.
Environment Variables
All hosting platforms need these environment variables:
| Variable | Required | Description |
|---|---|---|
BREASE_TOKEN | Yes | API authentication token |
BREASE_ENV | Yes | Environment UUID |
BREASE_DEFAULT_LOCALE | Yes | Default locale code (e.g. en) |
BREASE_REVALIDATION_TIME | No | ISR revalidation in seconds (default 30) |
Deploying to Vercel
Vercel is the recommended hosting platform for Next.js projects.
1. Set environment variables
In your Vercel project dashboard, go to Settings > Environment Variables and add:
BREASE_TOKENBREASE_ENVBREASE_DEFAULT_LOCALEBREASE_REVALIDATION_TIME(optional)
Set them for Production, Preview, and Development environments as needed.
2. Deploy
Push to your git repository. Vercel automatically builds and deploys:
git push origin main
Vercel handles the Node.js runtime, ISR, and edge caching automatically.
Deploying to Other Platforms
For platforms like Railway, Render, AWS, or self-hosted servers:
Requirements
- Node.js 18+ runtime
- Environment variables set in the platform's configuration
- Ability to run
npm run buildandnpm start
Deploy steps
# Install dependencies
npm ci
# Build the application
npm run build
# Start the production server
npm start
The production server defaults to port 3000. Configure the PORT environment variable if your platform requires a different port.
Robots.txt
Use generateBreaseRobots to create a robots.txt route based on your site configuration:
// src/app/robots.ts
import { generateBreaseRobots } from 'brease-next/server'
import type { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
return generateBreaseRobots('https://example.com')
}
generateBreaseRobots accepts a site URL and an optional options object:
const robots = generateBreaseRobots('https://example.com', {
// Additional options can be passed here
})
Sitemap
Use generateSitemap to create a dynamic sitemap from all published pages:
// src/app/sitemap.ts
import { generateSitemap } from 'brease-next/server'
import type { MetadataRoute } from 'next'
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const result = await generateSitemap()
if (!result.success) {
return []
}
return result.data
}
generateSitemap returns a BreaseResponse<MetadataRoute.Sitemap> containing URLs for all published pages across all locales.
CORS and Preview Mode
If you use Brease's live preview feature (where the CMS editor iframes your site), configure Content Security Policy headers to allow framing from the CMS domain:
// next.config.ts
const nextConfig = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: "frame-ancestors 'self' https://app.brease.io",
},
],
},
]
},
// ... other config
}
Restrict frame-ancestors in production
Only allow framing from domains you trust. The example above allows the Brease CMS (app.brease.io) to embed your site for preview purposes. Do not use frame-ancestors * in production.
Redirects
Redirects are fetched from the Brease API at build time and configured in next.config.ts:
// next.config.ts
import { fetchRedirects } from 'brease-next/server'
const nextConfig = {
async redirects() {
const result = await fetchRedirects()
if (!result.success) {
console.error('Failed to fetch redirects:', result.error)
return []
}
return result.data.map((redirect) => ({
source: redirect.source,
destination: redirect.destination,
permanent: redirect.type === '301' || redirect.type === '308',
}))
},
}
Redirects are baked into the build output. To update redirects after changing them in the CMS, trigger a new build or redeploy.
Deployment Checklist
Before going live, verify each item:
Environment
- [ ]
BREASE_TOKENis set on the hosting platform - [ ]
BREASE_ENVis set and points to the production environment - [ ]
BREASE_DEFAULT_LOCALEis set to the correct default locale - [ ]
BREASE_REVALIDATION_TIMEis set (or using the default of 30s)
Configuration
- [ ]
next.config.tshasremotePatternsfor the Brease media CDN - [ ]
next.config.tshas theredirects()function usingfetchRedirects - [ ]
robots.tsis configured withgenerateBreaseRobots - [ ]
sitemap.tsis configured withgenerateSitemap
CMS
- [ ] Preview domain is set in the Brease CMS settings (if using live preview)
- [ ] All pages are published in the target environment
- [ ] Structured data is configured for key pages (homepage, about, etc.)
Build
- [ ]
npm run buildcompletes without errors - [ ] All expected pages are pre-rendered (check build output)
- [ ] No missing section key warnings in the build log
- [ ] Images load correctly from the CDN
Verification
- [ ] Homepage renders correctly
- [ ] Navigation links work (internal and external)
- [ ] Multi-locale pages load the correct translations
- [ ] Redirects work as configured in the CMS
- [ ] Meta tags and Open Graph data appear in page source
- [ ] Structured data validates in Google's Rich Results Test
- [ ] 404 pages return the correct status code
Next Steps
- Project Setup Guide — review your initial configuration
- Structured Data & Custom Code — verify SEO output
- Multi-Locale Sites — ensure all locales deploy correctly