A Next.js app running on Harper with @harperfast/nextjs: a small "Doggy Management System" that lists, adds and deletes dogs stored in a Harper table.
Because the app runs inside Harper, its server-side code reads and writes the database directly through the Resource API, with no separate API server and no network round-trip.
- Clone this repository.
- Run
npm install. This also installs theharperCLI the scripts use, as a dev dependency. - Run
npm run dev. It runsnext build, then starts Harper with this app (harper dev .). - Open http://localhost:9926 🎉
This app is a Harper component. config.yaml loads two things:
graphqlSchemareadsschema.graphql, which defines theDogtable.- The
@harperfast/nextjsplugin runs the Next.js app inside Harper and serves it.
Server actions use Harper's globals. Harper injects tables and transaction globals into server-side code, so the server actions in app/actions.js use tables.Dog directly, with no import. Don't add import 'harper' to server code: that import runs during next build, where it conflicts with the database, and it does not survive a build made in CI. The globals exist only on the server, and only while Harper runs the app, so each action checks for the table first.
Putting the data access in server actions lets server and client components share it: the server component app/dogs/page.js calls listDogs and submits its form to createDog, and the client component app/ui/DeleteButton.js calls deleteDog. Any server action a client can reach is a public endpoint, and this example lets anyone add or delete a dog; add your own authorization checks before shipping mutations that matter.
Visitors' dogs don't last. Because anyone can add a dog, app/dogInput.js accepts only names, breeds and colors made of words, never links, and the form's inputs carry the same patterns. The Dog table also declares @table(expiration: 3600), so each dog expires an hour after it was written and Harper's periodic eviction sweep deletes it, with no cleanup job of the app's own. Until that sweep runs, /dogs can still list an expired dog, and changing or dropping the value affects only dogs written afterwards. See table expiration in Harper's docs.
The app is prebuilt. config.yaml sets prebuilt: true, so the plugin serves the .next that next build produced instead of building when Harper starts. Building on a Harper cluster currently fails (HarperFast/nextjs#57, HarperFast/nextjs#58), so every script that starts or deploys the app (dev, start, deploy, test:integration) runs next build first, and the workflows build in CI and deploy the result.
| Script | What it does |
|---|---|
npm run dev |
Builds, then runs the app in Harper. Run it again after an edit: it serves the build, without hot reloading. |
npm start |
Builds, then runs the app in Harper. |
npm run build |
Runs next build. |
npm run lint |
Runs ESLint. |
npm run deploy |
Builds, then deploys this directory to your cluster as the user you logged in with. |
npm run deploy:setup-ci |
One-time setup for deploying from GitHub Actions. |
npm run deploy:setup-previews |
One-time setup for pull request previews. |
npm run test:integration |
Builds, then boots the app in a throwaway Harper and runs integrationTests/. |
.github/workflows/deploy.yaml lints and builds every pull request, and deploys to your Harper cluster when a change merges to main. It stores no Harper password or token in GitHub: the deploy job uses HarperFast/deploy-action, which authenticates with the run's GitHub OIDC identity token, under a trust policy on the cluster. The build runs in the test job, and the deploy job uploads it, so your dependencies' install and build scripts never run where that token can be requested.
To set it up, push the project to GitHub, create a cluster (for example on Harper Fabric), and log the CLI in to it as a super user:
npx harper loginThen, from this directory, run the one-time setup. It needs the Harper 5.4 or later CLI, which npm install installed here as a dev dependency:
npm run deploy:setup-ciIt creates a deploy-only role and user, and a trust policy that accepts tokens from deploy.yaml on main in the production environment. With the gh CLI signed in, it also sets the HARPER_CLI_TARGET repository variable. Then merge to main, or run the workflow from the Actions tab. Deploying from CI explains how the workflow authenticates and what the setup creates.
This workflow replaces the earlier build-and-deploy.yml, which deployed with a username and password. Once the new workflow has deployed, delete its HDB_TARGET, HDB_USERNAME and HDB_PASSWORD secrets under Settings → Secrets and variables → Actions.
Each pull request from a branch of this repository can get its own copy of the app on the cluster, at its own URL. The URL is posted as a comment on the pull request, and the preview is dropped when the pull request closes. Pull requests from forks get no preview.
Previews use two workflows, because building runs the pull request's code and its dependencies' scripts, which must not happen in a job that can request the cluster's identity token:
preview-build.yamlruns onpull_requestwith a read-only token. It installs the dependencies, runsnext build, and uploads the app directory,.nextincluded, as an artifact.preview.yamlruns onpull_request_target, so it always runs as it is onmain, and it holds the identity token. It never checks out or runs the pull request's code: it waits for that commit's build, downloads it, and deploys the directory withHarperFast/deploy-action. When the pull request closes, its cleanup job drops the preview.
The app is uploaded rather than fetched by the cluster, because the commit has no .next in it and Next.js can't build on the cluster.
Previews need every node of the cluster on Harper 5.4 or later, and a cluster that can run isolated applications; see Per-PR previews for the requirements. To set them up:
-
Have both workflow files on
main. GitHub runs apull_request_targetworkflow as it is on the default branch, never as a pull request changes it. -
Under Settings → Environments, create a
previewenvironment for the deploy job and apreview-cleanupenvironment for the cleanup job, and allowmainunder each one's deployment branches. Add required reviewers topreviewif you want to approve each preview deploy; keep them offpreview-cleanup, so a closed pull request's preview is never left waiting for an approval. -
Log the CLI in to the cluster as a super user with
npx harper login, sign in to theghCLI, and run this once from this directory:npm run deploy:setup-previews
It checks
preview.yamland refuses a workflow that would give a fork or a pull request's code the preview identity. It then enables previews on the cluster and sets theHARPER_PREVIEW_TARGETrepository variable. Until that variable is set, the preview workflow does nothing.
This repository is public. From December 2, 2026, GitHub blocks pull_request_target in public repositories unless a policy allows it, so allow it for preview.yaml; see Allowing pull_request_target.
For what a Next.js app needs on top of Harper's previews, such as how previews share or branch the cluster's data and Next.js caches, see Pull request previews in the plugin's README.
@harperfast/nextjsfor the plugin's options.- Harper documentation for building and deploying Harper applications.