-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We add the ability to display templates.
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
force-pushed
the
add-views-to-system
branch
from
October 11, 2022 14:58
b8fff41
to
ec2adff
Compare
Jozzey
approved these changes
Oct 12, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 inhapi-web-boilerplate
.Building assets is done in the exact same way as the boilerplate app:
npm run build
calls a bash scriptbin/build
. This script is intended to run whatever build stages are needed, but at present it only runsnpm run build:css
.npm run build:css
usesnode-sass
to compile the sass stylesheet currently inclient/sass/application.scss
(which simply links to thegovuk-frontend
stylesheet) to standard css inapp/public/build
. Note that we update.gitignore
so that this folder isn't checked in.postinstall
script is added topackage.json
so thatnpm run build
is automatically run after annpm ci
ornpm install
.A few points to bear in mind for potential future changes:
client/sass/application.scss
where we want our sass stylesheet to live?/robots.txt
(currently living inapp/public/static/robots.txt
). In the existing UI we have ano-robots
plugin which serves this up on request without needing a static file to be stored. Do we want to do this instead?ErrorPagesPlugin
to ensure it correctly logs 500 errors; for now we've simply copied the error format inhapi-web-boilerplate
, adapting it to use our own logger.hapi-web-boilerplate
.