# Headless sites

> Render your blog with your own frontend, using Quillhive as the CMS and API.

A site is either **hosted** or **headless**.

- **Hosted** (the default): Quillhive renders the blog on its free address or your custom domain.
- **Headless**: your own frontend renders it from the [Content API](/docs/api) and stays fresh with [webhooks](/docs/webhooks). Quillhive is the editor and the API.

Switch modes in **Settings → Developer → Domains** (admins only).

## Settings

| Setting | Meaning | Example |
| --- | --- | --- |
| Frontend URL | Where your frontend lives. A base path is allowed | `https://example.com` |
| Post URL pattern | Where a published post lives. Defaults to `{slug}` | `/blog/{slug}` |
| Page URL pattern | Where a published page lives. Defaults to `{slug}` | `/{slug}` |
| Preview URL pattern | Where to see an unpublished post or page. No default | `/preview/{uuid}` |

Placeholders: `{slug}`, `{id}`, `{uuid}` and `{type}` (`post` or `page`). Values are URL-encoded.

A pattern resolves against the frontend URL the way a link does. With a frontend URL of `https://example.com/blog`:

| Pattern | Resolves to |
| --- | --- |
| `/post/{slug}` (leading `/`) | `https://example.com/post/hello-world` |
| `post/{slug}` (no leading `/`) | `https://example.com/blog/post/hello-world` |
| `https://news.example.com/{slug}` | Used as is |

The [Site endpoint](/docs/api/sites) returns `headless`, `frontendUrl`, `postUrlPattern` and `pageUrlPattern`, so your frontend can build the same links. The preview pattern is never public, because it may carry a secret.

## What changes in headless mode

| | Hosted | Headless |
| --- | --- | --- |
| **View site** in the dashboard | Your blog's address | Your frontend URL |
| **View post** / **View page** | `/{slug}` on the hosted blog | Your post and page patterns |
| **Preview** on drafts | The hosted blog | Your preview pattern; hidden until set |
| Domains page | Connect custom domains | Mode and frontend URL only |
| The free address | Serves the blog | Redirects to the same path on your frontend |

Custom domains connected before the switch are kept but not used. Point their DNS at your frontend instead. Switching back to hosted restores them.

## Build a frontend

1. Get your site ID from **Settings → Developer → API**.
2. Fetch content from the [Content API](/docs/api): the site with its menus, posts (paginated), single posts by slug, pages, tags and authors.
3. Render `post.html` as the body. It's ready-made HTML.
4. Use the site's SEO fields for `<title>`, meta and social tags. See [Sites](/docs/api/sites#fields-worth-knowing) for the fallbacks.
5. Cache responses, and register a [webhook](/docs/webhooks) to drop the cache when content changes.
6. Turn on headless mode and set your URL patterns so the dashboard links to your pages.

## Draft previews on your frontend

1. Create an API key under **Settings → Developer → API**. Keep it on your server.
2. Add a preview route, for example `/preview/[uuid]`. On the server, load the draft from the [preview endpoint](/docs/api/posts#preview-a-post) with the key, and render it without caching and with `noindex`.
3. Set **Preview URL** to that route, for example `/preview/{uuid}`.

The editor's **Preview** button then opens drafts on your frontend.

> [!WARNING]
> A `uuid` is random, so the link works as a share-by-link preview. If drafts must stay private, add your own check, such as a signed-in session or a secret in the URL.
