Alinea integrates with Next.js through three exports fromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/alineacms/alinea/llms.txt
Use this file to discover all available pages before exploring further.
alinea/next: createCMS wraps your config into a Next.js-aware CMS instance, createHandler produces a single request handler function that you assign to the App Router GET and POST exports, and withAlinea patches your Next.js config to wire up dashboard routing. Together these three pieces are everything you need to run the Alinea editor alongside your application.
createCMS
createCMS accepts the same Config object documented in the configuration section and returns a NextCMS instance. NextCMS extends the base CMS class with Next.js-specific behaviour: it reads draft-mode cookies, uses the bundled local database during production builds, and exposes a previews() helper for rendering the floating preview widget.
Place your CMS config in a dedicated file (conventionally src/cms.ts or src/cms.tsx) that can be imported by both your application code and the API route.
src/cms.ts
The
handlerUrl in your CMS config must match the path where you mount the
route handler. The default value is /api/cms. If you change one, change the
other — a mismatch causes a 400 error at runtime.createHandler
createHandler creates the standard Next.js App Router route handler for the Alinea editing API. It returns a single Handler function (request: Request) => Promise<Response> that handles both GET and POST requests. Create an API route at app/api/cms/route.ts (or wherever handlerUrl points) and assign the handler to both named exports:
app/api/cms/route.ts
createHandler accepts either a NextCMS instance directly (shorthand) or a NextHandlerOptions object:
The
NextCMS instance created by createCMS. This is the only required
field.Optional self-hosted backend configuration. Provide this when you want Alinea
to commit content directly to GitHub and store drafts in your own database,
instead of routing through Alinea Cloud. See the
Backend Options page for the full shape of
this object.
A factory function that receives the current request context and returns a
custom
RemoteConnection. Use this for advanced scenarios where neither Cloud
nor the built-in GitHub backend fits. When omitted and no backend is
provided, CloudRemote is used automatically.Called before a new entry is created. Return a modified entry to override
it, or throw to abort the operation.
Called after a new entry is successfully created. Use for side effects.
Called before an existing entry is updated. Return a modified entry to
override it, or throw to abort.
Called after an entry is successfully updated. Use for side effects.
Called before an entry is archived. Throw to abort the operation.
Called after an entry is successfully archived.
Called before an entry is permanently removed. Throw to abort.
Called after an entry is permanently removed.
Handler behaviour
The handler performs two special tasks beyond forwarding API calls to the backend:- Preview redirect — When a request arrives with a
?preview=<token>query parameter, the handler verifies the JWT, enables Next.js Draft Mode, and redirects to the target URL. This is the entry point for the iframe preview flow. - Path enforcement — Requests whose path does not start with
handlerUrlreceive a400response immediately.
withAlinea
Wrap your next.config.ts export with withAlinea to enable dashboard routing:
next.config.ts
withAlinea merges its additions non-destructively:
next.config.ts
withAlinea makes the following changes to your config:
- Rewrites — In production, adds a rewrite so that a request to the dashboard path is served from the pre-built
admin.htmlstatic file. In development, the request is proxied to the Alinea dev server. - Remote patterns — Adds
uploads.alinea.cloudtoimages.remotePatternsso Next.js Image serves cloud-hosted media. - Server external packages — Marks
@alinea/generatedas a server external package (serverExternalPackageson Next 15+,serverComponentsExternalPackageson Next 14).
/admin) is read automatically from the generated @alinea/generated/settings.json file produced by alinea build. If the file is not present, dashboard routing is disabled and a warning is logged. You cannot override the dashboard path by passing an option to withAlinea — it is always derived from the generated settings.
Environment variables
| Variable | Description |
|---|---|
ALINEA_API_KEY | Your Alinea Cloud project key. Used to authenticate the handler with Alinea Cloud. In development, Alinea falls back to "dev" when this is unset. Set it in production to connect to your Cloud project. |
ALINEA_DEV_SERVER | Set automatically by the Alinea CLI in development; proxies dashboard asset requests to the local dev server. Do not set manually. |