> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reliantlabs.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy Next.js with Reliant Forge

> Deploy a Next.js app as a static export to Reliant's free static hosting and CDN, or, when it needs a server (server actions, middleware, API routes), as a container from its Dockerfile.

Reliant hosting serves Next.js two ways, and you pick by what the app uses. A **static export** (`output: "export"`) is a folder of HTML and JS on the free static hosting and CDN. An app that needs a server at request time (server actions, middleware, route handlers that answer dynamically, `cookies()`, ISR, `next/image` optimization) runs as a container built from its Dockerfile, like any other backend. This guide covers both. It was run at Forge `v1.10.1-0.20261123064811-54313eead62f`.

## Before you begin

* Node.js, and the app in a git repository.
* Forge: `reliant forge` inside Reliant, or `npx -y @reliantlabs/forge@latest` anywhere else.
* Static: nothing to pay (one hosted static site per person is free). Server: a Reliant account with [app hosting billing](https://docs.reliantlabs.io/hosting/overview.md#billing).

## Path 1: a static export

Set the export in `next.config.mjs`:

```js next.config.mjs theme={null}
export default {
  output: "export",
  images: { unoptimized: true },
};
```

`next build` then writes `out/`, which is what Forge publishes. Every route is rendered at build time, so a dynamic segment like `app/posts/[slug]/page.js` needs a `generateStaticParams()` listing every slug. When the values exist only at runtime (records in your API), move the id into the query string: `/posts/view?slug=…`, read with `useSearchParams`.

**1. Adopt and lint**

```bash terminal theme={null}
reliant forge project new --in-place --kind site --name my-site
reliant forge lint --static-export
```

The lint names everything the export refuses, with its file and line, before `next build` does. On our test app:

```text Output (trimmed) theme={null}
❌ static-export — 1 error
   ✗ app/posts/[slug]/page.js:1 [static-export-dynamic-segment] /posts/[slug] is a dynamic route ([slug]) with no generateStaticParams: an export renders every page at build time, so `next build` refuses it
```

Fix each finding until the lint passes, then `npm run build`, which is the authority.

**2. Deploy**

Signed in:

```bash terminal theme={null}
reliant forge env build prod --release v0.1.0
reliant forge env deploy prod v0.1.0
```

With no account, `npx -y @reliantlabs/forge@latest env deploy prod --claimable` adopts the app if needed and publishes it, with a claim link valid for 72 hours. See [Deploy without an account](https://docs.reliantlabs.io/forge/deploy-without-an-account.md).

**3. Verify**

```bash terminal theme={null}
reliant forge env status prod
curl -sI https://<your-host>/
```

An unknown path with no extension falls back to `index.html` (200), a missing file with an extension is 404.

## Path 2: a Next.js server, from its Dockerfile

If the lint reports server actions, middleware or `cookies()`, and removing them isn't an option, deploy the app as a service. Forge's lint says this itself when the config isn't an export: "a Next.js server is a process, so it ships as a workload". Use Next's standalone output and a Dockerfile:

```dockerfile Dockerfile theme={null}
FROM node:22-slim AS build
WORKDIR /app
COPY . .
RUN npm ci && npm run build

FROM node:22-slim
WORKDIR /app
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
USER node
ENV PORT=3000 HOSTNAME=0.0.0.0
EXPOSE 3000
CMD ["node", "server.js"]
```

with `output: "standalone"` in `next.config.mjs`. `HOSTNAME=0.0.0.0` matters: the standalone server otherwise binds the container's hostname only. Then adopt it as an app, not a site:

```bash terminal theme={null}
reliant forge project new --in-place --kind app --dry-run
```

```text Output (trimmed) theme={null}
Detected:
  - workload api (service): builds Dockerfile, port 3000
```

Write the files without `--dry-run`, then `docker build .`, `reliant forge env render prod`, and `reliant forge env deploy prod --yes`. Without billing it is queued, exit **7**, with the billing link. A Next server needs more than the anonymous plan's 128 MiB, so deploy it signed in. Verify with `reliant forge env status prod`, a `curl` of a server-rendered page, and `reliant forge obs check prod --wait --json` (exit **0** proven good, **1** regressed, **2** not proven, **8** the wait ran out; without OpenTelemetry it is 2, not proven good).

Don't adopt a server app with `--kind site`: it is accepted, but every env then fails `lint --static-export` with `static-export-not-exported` and `env render` refuses the binding.

## Next.js gotchas

* **`next/image` without `unoptimized`** fails the export: there is no image server.
* **`NEXT_PUBLIC_*`** is baked into the build, and public. Per-env values that must change without a rebuild go in `runtime_config` (served as `/config.js`); see [Deploy a static site](https://docs.reliantlabs.io/guides/forge/deploy-static-site-cdn.md).
* **Route handlers** (`app/api/*/route.ts`) are allowed in an export only as `GET` with `export const dynamic = "force-static"`.

See also: [Adopt an existing Vite or Next.js app](https://docs.reliantlabs.io/guides/forge/adopt-existing-vite-nextjs.md), [Deploy Express](https://docs.reliantlabs.io/guides/forge/deploy-express.md), [Hosting limits](https://docs.reliantlabs.io/hosting/limits.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.