Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add views to system #4

Merged
merged 15 commits into from
Oct 12, 2022
Merged

Add views to system #4

merged 15 commits into from
Oct 12, 2022

Conversation

StuAA78
Copy link
Contributor

@StuAA78 StuAA78 commented Oct 10, 2022

DEFRA/water-abstraction-team#54

The first step to moving the service status page from the UI to our new system is to implement views. We do this using https://github.com/DEFRA/hapi-web-boilerplate as a basis to work from.

Once implemented, we add a simple /hello-world page, based on the example in hapi-web-boilerplate.

Building assets is done in the exact same way as the boilerplate app:

  • npm run build calls a bash script bin/build. This script is intended to run whatever build stages are needed, but at present it only runs npm run build:css.
  • npm run build:css uses node-sass to compile the sass stylesheet currently in client/sass/application.scss (which simply links to the govuk-frontend stylesheet) to standard css in app/public/build. Note that we update .gitignore so that this folder isn't checked in.
  • A postinstall script is added to package.json so that npm run build is automatically run after an npm ci or npm install.

A few points to bear in mind for potential future changes:

  • Is client/sass/application.scss where we want our sass stylesheet to live?
  • We've followed the model of the boilerplate app and serve a static file for /robots.txt (currently living in app/public/static/robots.txt). In the existing UI we have a no-robots plugin which serves this up on request without needing a static file to be stored. Do we want to do this instead?
  • We probably want to double-check the ErrorPagesPlugin to ensure it correctly logs 500 errors; for now we've simply copied the error format in hapi-web-boilerplate, adapting it to use our own logger.
  • Google Analytics hasn't yet been brought over from hapi-web-boilerplate.

We add the ability to display templates.
@StuAA78 StuAA78 added the enhancement New feature or request label Oct 10, 2022
@StuAA78 StuAA78 self-assigned this Oct 10, 2022
We create our `ViewsPlugin` which serves up views using nunjucks. Since this relies on being able to serve up static assets (eg. stylesheets) we also add the required routes.
We create a route for a `/hello-world` page, based on the example in `hapi-web-boilerplate`
We set a default page title in `ViewsPlugin` but this can be overridden by adding `pageTitle` to the `h.view()` call in a controller. We therefore add a sample page title to our `/hello-world` page.
The boilerplate example uses `.html` as the file extension for views. The nunjucks community has adopted `.njk` as the file extension of choice (and this is the extension used in the current service). We therefore update our files to use this extension instead.
Although `h.view()` doesn't need the file extension of our template file, we add it anyway as this will help us in future when looking for where a specific template is used; easier to search for `home.njk` than just `home`.
We add comments to `ViewsPlugin` to explain some of the options
We make the `isCached` option in `ViewsPlugin` dependent on the environment; caching is disabled in dev, and enabled in all other environments
@StuAA78 StuAA78 force-pushed the add-views-to-system branch from b8fff41 to ec2adff Compare October 11, 2022 14:58
@StuAA78 StuAA78 marked this pull request as ready for review October 11, 2022 16:21
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@StuAA78 StuAA78 merged commit 83b6fa1 into main Oct 12, 2022
@StuAA78 StuAA78 deleted the add-views-to-system branch October 12, 2022 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants