An introduction to building a hapi service using the govuk plugins (by example) for the hapi Node.js framework.
Please note these examples have been developed from what was learned while developing the permitting proof of concept which is a good reference point if anything is not clear here.
- Node v12+ (The best way to install Node is via NVM)
- The frontend tutorial using the @envage/hapi-govuk-frontend plugin
- The journey map tutorial using the @envage/hapi-govuk-journey-map plugin
- The question page tutorial using the @envage/hapi-govuk-question-page plugin
- The essential plugins tutorial
- The back link plugin
- The csrf crumb plugin using the @hapi/crumb plugin
- The session cache plugin using the @hapi/yar plugin
- The logging plugin using the defra-logging-facade plugin
- The form validation module
- The service status plugin using the hapi-version-status plugin
- The robots plugin using the hapi-robots plugin
- The blipp plugin using the blipp plugin
Provides a simple way to configure the locations of static files, dynamic view layouts and view partials for a hapi server.
The plugin assumes that Nunjucks will be used as the view engine.
The govuk-frontend npm module should be installed as a peer dependency.
-
- Prepare your environment
-
- Create the example project including a hapi server with one route
-
- Introduce the @envage/hapi-govuk-frontend plugin.
- Create a home page by modifying the route in the example project with a nunjucks view using the GOV-UK design system.
-
- Break the hapi server within the example project into component parts
Provides a way to organise the routes in a hapi server into reusable modules. Using mapping files, the plugin also provides a way to create journeys within and between each module instance.
-
Journey map example introduction
- Introduction to the journey map
-
- Without using the Journey map plugin, add a continue button using the nunjucks macro govukButton.
- Clicking the button should redirect to the next page in the journey.
-
- Again without using the Journey map plugin, create a question page including the nunjucks macro govukRadios and again include a continue button as above to redirect to the next page in the journey.
-
- One more time without using the Journey map plugin, create a completed page including the nunjucks macro govukPanel.
-
- Introduce the @envage/hapi-govuk-journey-map plugin.
- Create a map file to configure the journey between routes.
- Rearrange the location of the views and routes into a module folder.
-
- Configure the map file to allow branching the journey based on the answer given in the question page.
-
- Introduce the concept of modules to allow re-use of routes and views.
- Move the question route into a new question module.
- Include a new comment route within the question module.
- Create a map file within the question module.
- Configure the main map file to use the question module.
-
- Introduce the concept of module options as a means of configuring a module.
- Add the options to the registration of the question module within the main map file.
- Change the route files for both the question and comment routes to use the options.
-
- Re-use the question module by registering it twice more in the main map file with different module options.
Provides a configuration-driven approach to implementing simple pages using the GOV.UK Design System.
- Question page example introduction
- Introduction to question pages
If you have an idea you'd like to contribute please log an issue.
All contributions should be submitted via a pull request.
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
The following attribution statement MUST be cited in your products and applications when using this information.
Contains public sector information licensed under the Open Government license v3
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.