Skip to content

Commit 7932c8c

Browse files
committed
fix(docs): correct code bugs and add missing SESSION_COOKIE_PASSWORD
- Add missing node:path, @hapi/vision and nunjucks imports to Step 3 - Add @hapi/vision registration block (was listed as a dependency but never shown being registered in the full example) - Fix viewContext return object: missing comma and string key syntax - Add SESSION_COOKIE_PASSWORD as a required env var in Step 5
1 parent 0c934e0 commit 7932c8c

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

docs/getting-started.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ await server.register({
6767
Full example:
6868

6969
```javascript
70+
import { join } from 'node:path'
7071
import hapi from '@hapi/hapi'
72+
import vision from '@hapi/vision'
7173
import yar from '@hapi/yar'
7274
import crumb from '@hapi/crumb'
7375
import inert from '@hapi/inert'
7476
import pino from 'hapi-pino'
77+
import nunjucks from 'nunjucks'
7578
import plugin from '@defra/forms-engine-plugin'
7679

7780
const server = hapi.server({
@@ -93,6 +96,23 @@ await server.register({
9396

9497
const paths = [join(config.get('appDir'), 'views')]
9598

99+
await server.register({
100+
plugin: vision,
101+
options: {
102+
engines: {
103+
html: {
104+
compile(path, { environment }) {
105+
return (context) => nunjucks.compile(path, environment).render(context)
106+
}
107+
}
108+
},
109+
path: paths,
110+
compileOptions: {
111+
environment: nunjucks.configure(paths)
112+
}
113+
}
114+
})
115+
96116
// Register the `forms-engine-plugin`
97117
await server.register({
98118
plugin,
@@ -120,8 +140,8 @@ await server.register({
120140
const user = await userService.getUser(request.auth.credentials)
121141

122142
return {
123-
"greeting": "Hello" // available to render on a nunjucks page as {{ greeting }}
124-
"username": user.username // available to render on a nunjucks page as {{ username }}
143+
greeting: 'Hello', // available to render on a nunjucks page as {{ greeting }}
144+
username: user.username // available to render on a nunjucks page as {{ username }}
125145
}
126146
}
127147
}
@@ -156,6 +176,12 @@ Example: https://github.com/DEFRA/forms-runner/blob/24c5623946cdfddca593bcba8a68
156176

157177
## Step 5: Environment variables
158178

179+
The following variable is always required:
180+
181+
```shell
182+
SESSION_COOKIE_PASSWORD=your-secret-password-at-least-32-chars
183+
```
184+
159185
Blocks marked with `# FEATURE: <name>` are optional and can be omitted if the feature is not used.
160186

161187
```shell

0 commit comments

Comments
 (0)