Skip to content

Commit a754a8c

Browse files
Update example
- Separate out data to be loaded independently - Add a CI/CD workflow for deploying - Tweak application
1 parent d6f7212 commit a754a8c

File tree

8 files changed

+116
-39
lines changed

8 files changed

+116
-39
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build and Deploy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Install Harper CLI
26+
run: npm install -g harperdb
27+
28+
- name: Setup Harper
29+
env:
30+
TC_AGREEMENT: 'yes'
31+
HDB_ADMIN_USERNAME: 'admin'
32+
HDB_ADMIN_PASSWORD: 'password'
33+
ROOTPATH: '/tmp/hdb'
34+
OPERATIONSAPI_NETWORK_PORT: 9925
35+
LOGGING_LEVEL: 'debug'
36+
LOGGING_STDSTREAMS: true
37+
THREADS_COUNT: 1
38+
THREADS_DEBUG: false
39+
run: harperdb install
40+
41+
- name: Deploy data
42+
run: |
43+
harperdb start
44+
sleep 10
45+
harperdb deploy project=basic-data package=HarperDB/basic-data-example replicated=true
46+
sleep 10
47+
harperdb stop
48+
49+
- name: Build project
50+
run: npm run build
51+
52+
- name: Add prebuilt flag to config
53+
run: yq e '.["@harperdb/nextjs"].prebuilt = true' -i config.yaml
54+
55+
- name: Upload HarperDB logs
56+
if: always()
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: harperdb-logs
60+
path: /tmp/hdb/log/hdb.log
61+
retention-days: 7
62+
63+
- name: Deploy
64+
env:
65+
HDB_TARGET: ${{ secrets.HDB_TARGET }}
66+
HDB_USERNAME: ${{ secrets.HDB_USERNAME }}
67+
HDB_PASSWORD: ${{ secrets.HDB_PASSWORD }}
68+
run: |
69+
harperdb deploy \
70+
target="$HDB_TARGET" \
71+
username="$HDB_USERNAME" \
72+
password="$HDB_PASSWORD" \
73+
project=nextjs-example \
74+
skip_node_modules=false \
75+
restart=true \
76+
replicated=true

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
# HarperDB Next.js Example
1+
# Harper Next.js Example
22

3-
This is an example of how to use [`@harperdb/nextjs`](https://github.com/HarperDB/nextjs) to develop a Next.js application with HarperDB.
3+
This is an example of how to use [`@harperdb/nextjs`](https://github.com/HarperDB/nextjs) to develop a Next.js application with Harper.
44

55
The Next.js application can interact with the database through the [Resource API](https://docs.harperdb.io/docs/technical-details/reference/resource) directly instead of relying on network operations. This is significantly more efficient and enables a better application development experience.
66

7+
<!--
8+
TODO: Re-record video with new application steps
79
> [!TIP]
810
> Watch a walkthrough of this example here: [Next.js on HarperDB | Step-by-Step Guide for Next Level Next.js Performance](https://youtu.be/GqLEwteFJYY)
11+
-->
12+
13+
This example requires the [Harper Basic Data Example](https://github.com/HarperDB/basic-data-example) in order to function. Please follow the instructions in that repo to set up HarperDB with the necessary data before running this example.
914

1015
## Get Started
1116

@@ -14,9 +19,32 @@ The Next.js application can interact with the database through the [Resource API
1419
3. Run `npm run dev`
1520
4. Open [http://localhost:9926](http://localhost:9926) 🎉
1621

22+
### Remote Deployment
23+
24+
The easiest way to demonstrate this application remotely is to use the `prebuilt: true` option and the [Harper CLI](https://docs.harperdb.io/docs/deployments/harper-cli#operations-api-through-the-cli).
25+
26+
1. Locally or in a CI environment, load the necessary data ([Harper Basic Data Example](https://github.com/HarperDB/basic-data-example))
27+
2. Create a build using `npm run build`
28+
3. Modify `config.yaml` to include `prebuilt: true` under the `@harperdb/nextjs` component
29+
5. Then deploy the prebuilt application using the Harper CLI:
30+
31+
```bash
32+
harperdb deploy \
33+
target="<operations api url>" \
34+
username="<username>" \
35+
password='<password>' \
36+
project=nextjs-example \
37+
package=HarperDB/nextjs-example \
38+
skip_node_modules=false \
39+
replicated=true \
40+
restart=true
41+
```
42+
43+
Check out the included [build and deploy workflow](./.github/workflows/deploy.yml) for an example of how to automate this process.
44+
1745
## How does it work?
1846

19-
This example in and of itself is a [HarperDB Component](https://docs.harperdb.io/docs/developers/components), and is reliant on the `@harperdb/nextjs` extension in order to access to the [HarperDB Globals](https://docs.harperdb.io/docs/technical-details/reference/globals). The globals are only available on server-side code paths such as [server actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations) and [server components](https://nextjs.org/docs/app/building-your-application/rendering/server-components). Any code paths using HarperDB globals must first import the `harperdb` package (i.e. `import('harperdb')`).
47+
This example in and of itself is a [HarperDB Component](https://docs.harperdb.io/docs/developers/components), and is reliant on the `@harperdb/nextjs` extension in order to access the [Harper Resource API](https://docs.harperdb.io/docs/technical-details/reference/resources). The globals are only available on server-side code paths such as [server actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations) and [server components](https://nextjs.org/docs/app/building-your-application/rendering/server-components). Any code paths using HarperDB globals must first import the `harperdb` package (i.e. `import('harperdb')`).
2048

2149
> [!TIP]
2250
> Use the `harperdb-nextjs` CLI (part of the `@harperdb/nextjs` package) to replace the Next.js CLI. For example, `next dev` becomes `harperdb-nextjs dev`. This CLI handles running HarperDB and providing sensible configuration values for the `@harperdb/nextjs` component.

app/layout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Link from 'next/link';
22

33
export const metadata = {
4-
title: 'HarperDB - Next.js App',
4+
title: 'Harper - Next.js App',
55
};
66

77
export default function RootLayout({ children }) {
88
return (
99
<html lang="en">
10-
<body style={{ width: '500px', fontFamily: 'sans-serif' }}>
10+
<body style={{ width: '800px', fontFamily: 'sans-serif' }}>
1111
<header>
1212
<nav>
1313
<ul
@@ -29,7 +29,7 @@ export default function RootLayout({ children }) {
2929
</header>
3030
<main>
3131
<section style={{ borderBottom: '1px solid' }}>
32-
<h1>HarperDB Next.js Example Application</h1>
32+
<h1>Harper Next.js Example Application</h1>
3333
<p>This application demonstrates multiple distinct Next.js features.</p>
3434

3535
<p>Use the navigation links to try different page types.</p>

config.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
graphqlSchema:
2-
files: 'schema.graphql'
3-
jsResource:
4-
files: 'resources.js'
51
'@harperdb/nextjs':
62
package: '@harperdb/nextjs'
7-
files: '/*'
3+
files: '*'

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"format": "prettier --write ."
1111
},
1212
"dependencies": {
13-
"@harperdb/nextjs": "1.1.3",
13+
"@harperdb/nextjs": "1.1.4",
1414
"next": "15.3.3",
1515
"react": "18",
1616
"react-dom": "18"

resources.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

schema.graphql

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)