Next.js integration
Helpers for ISR, sitemap generation, and route handlers in Next.js App Router.
The inventra/next sub-export has helpers for Next.js App Router: ISR caching, sitemap generation, and pre-built route handlers.
withISR(seconds)
Returns a FetchConfig object that enables Next.js ISR on any SDK call. Pass it into the method you want cached — the Next.js fetch cache picks up the directive automatically.
import { withISR } from 'inventra/next';
import { inventra } from '@/packages/plugins/config';
const posts = await inventra.contents.list(withISR(3600)); // revalidate every hour
const post = await inventra.contents.getBySlug(slug, withISR(60));For page-level ISR, use the native Next.js directive — withISR() is only for SDK method calls.
// app/blog/[slug]/page.tsx
export const revalidate = 60;createSitemapGenerator(inventra, config)
Returns a function compatible with Next.js app/sitemap.ts that merges your static routes with every blog entry from Inventra.
// app/sitemap.ts
import { createSitemapGenerator, withISR } from 'inventra/next';
import { inventra } from '@/packages/plugins/config';
export default createSitemapGenerator(inventra, {
baseUrl: 'https://example.com',
staticRoutes: [
{ path: '/', priority: 1 },
{ path: '/about', priority: 0.8 },
{ path: '/blog', priority: 0.9, changeFrequency: 'daily' }
],
fetchConfig: withISR(3600) // cache the blog list for an hour
});Config
| Option | Type | Description |
|---|---|---|
baseUrl |
string |
Absolute base URL. No trailing slash. |
staticRoutes |
{ path, priority?, changeFrequency? }[] |
Your own pages (home, about, products, etc.). Path is the pathname, e.g. /about. |
blogBasePath |
string |
Where blog slugs are served. Defaults to /blog. |
fetchConfig |
FetchConfig |
Optional. Pass withISR(seconds) to cache the blog list between sitemap rebuilds. |
Route handlers
For websites that want to expose a public read-only API mirroring Inventra (e.g. for a mobile app), the SDK provides pre-built route handlers:
// app/api/contents/route.ts
import { createContentsHandler } from 'inventra/next';
import { inventra } from '@/packages/plugins/config';
export const GET = createContentsHandler(inventra);Available: createContentsHandler, createCategoriesHandler, createContactHandler (accepts an optional Zod schema for validation).
Recommended project structure
Centralise the SDK instance alongside your site metadata and OG theme in one file — packages/plugins/config.ts — and import from it everywhere:
// packages/plugins/config.ts
import { Inventra } from 'inventra';
import { env } from '@/env';
export const inventra = new Inventra({
apiKey: env.INVENTRA_API_KEY,
orgId: env.INVENTRA_ORG_ID
});import { inventra } from '@/packages/plugins/config';See the SEO setup guide for the full pattern — sitemap, robots, llms.txt, JSON-LD, canonical URLs, and OpenGraph wired up end-to-end.