Skip to content

Commit 69a8a0c

Browse files
colinrotherhampaulrobertlloyd
authored andcommitted
Update prototype kit
1 parent 954edc4 commit 69a8a0c

9 files changed

Lines changed: 805 additions & 724 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66

77
.data
88
/node_modules
9-
/assets
109
/public

app.js

Lines changed: 37 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,53 @@
1-
// External dependencies
2-
import express from 'express'
3-
import nunjucks from 'nunjucks'
41
import sessionInDatabase from 'connect-pg-simple'
2+
import express from 'express'
53
import session from 'express-session'
6-
import { Pool } from 'pg'
7-
8-
import { join } from 'node:path'
9-
104
import NHSPrototypeKit from 'nhsuk-prototype-kit'
5+
import { Pool } from 'pg'
116

12-
const serviceName = 'Manage vaccinations in schools'
13-
14-
// Local dependencies
15-
import routes from './app/routes.js'
16-
import filters from './app/filters.js'
177
import sessionDataDefaults from './app/data.js'
8+
import filters from './app/filters.js'
9+
import globals from './app/globals.js'
10+
import routes from './app/routes.js'
1811

19-
// Set configuration variables
20-
const port = parseInt(process.env.PORT, 10) || 2000
12+
const { DATABASE_URL, NODE_ENV } = process.env
2113

22-
// Initialise applications
2314
const app = express()
2415

25-
26-
const sessionName = `manage-vaccinations-in-schools-prototype`
27-
const sessionOptions = {
28-
secret: sessionName,
29-
cookie: {
30-
maxAge: 1000 * 60 * 60 * 4, // 4 hours
31-
secure: process.env.NODE_ENV === 'production'
32-
}
33-
}
34-
35-
const PgSession = sessionInDatabase(session)
36-
const pool = new Pool({
37-
connectionString: process.env.DATABASE_URL,
38-
ssl:
39-
process.env.NODE_ENV === 'production'
40-
? {
41-
rejectUnauthorized: false
42-
}
43-
: false
44-
})
45-
4616
app.use(
47-
session(
48-
Object.assign(sessionOptions, {
49-
store: new PgSession({ pool }),
50-
resave: false,
51-
saveUninitialized: false
17+
session({
18+
cookie: {
19+
maxAge: 1000 * 60 * 60 * 4, // 4 hours
20+
secure: process.env.NODE_ENV === 'production'
21+
},
22+
resave: false,
23+
saveUninitialized: false,
24+
secret: 'manage-vaccinations-in-schools-prototype',
25+
store: new (sessionInDatabase(session))({
26+
pool: new Pool({
27+
connectionString: DATABASE_URL,
28+
ssl: NODE_ENV === 'production' ? { rejectUnauthorized: false } : false
29+
})
5230
})
53-
)
31+
})
5432
)
5533

56-
// Nunjucks configuration for application
57-
const appViews = [
58-
join(import.meta.dirname, 'app/views/'),
59-
join(import.meta.dirname, 'node_modules/nhsuk-frontend/dist/nhsuk/components'),
60-
join(import.meta.dirname, 'node_modules/nhsuk-frontend/dist/nhsuk/macros'),
61-
join(import.meta.dirname, 'node_modules/nhsuk-frontend/dist/nhsuk'),
62-
join(import.meta.dirname, 'node_modules/nhsuk-frontend/dist'),
63-
join(import.meta.dirname, 'node_modules/nhsuk-decorated-components')
64-
]
65-
66-
const nunjucksConfig = {
67-
autoescape: true,
68-
noCache: true
69-
}
70-
71-
nunjucksConfig.express = app
72-
73-
let nunjucksAppEnv = nunjucks.configure(appViews, nunjucksConfig)
74-
75-
// Use public folder for static assets
76-
app.use(express.static(join(import.meta.dirname, 'public')))
77-
78-
// Use assets from NHS frontend
79-
app.use(
80-
'/nhsuk-frontend',
81-
express.static(join(import.meta.dirname, 'node_modules/nhsuk-frontend/dist/nhsuk'))
82-
)
83-
84-
const prototype = NHSPrototypeKit.init({
85-
serviceName: serviceName,
86-
express: app,
87-
nunjucks: nunjucksAppEnv,
88-
routes: routes,
34+
const prototype = await NHSPrototypeKit.init({
35+
serviceName: 'Manage vaccinations in schools',
36+
app,
8937
buildOptions: {
90-
entryPoints: ['app/assets/stylesheets/application.scss', 'app/assets/stylesheets/prototype.scss', 'app/assets/stylesheets/public.scss']
91-
}
38+
entryPoints: [
39+
'app/assets/stylesheets/*.scss',
40+
'app/assets/javascripts/*.js'
41+
]
42+
},
43+
viewsPath: ['app/views', 'node_modules/nhsuk-decorated-components'],
44+
routes,
45+
filters,
46+
sessionDataDefaults
9247
})
9348

94-
prototype.start()
49+
for (const [key, value] of Object.entries(globals())) {
50+
prototype.nunjucks?.addGlobal(key, value)
51+
}
52+
53+
prototype.start(2000)

app.json

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

app/filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
* @returns {object} Filters
1717
*/
1818
export default (env) => {
19-
const filters = {}
19+
const filters = prototypeFilters
2020

2121
/**
2222
* Remove border from last summary row

app/views/_layouts/default.njk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "rig/default.njk" %}
1+
{% extends "prototype-kit-template.njk" %}
22

33
{#- App macros -#}
44
{% from "_macros/action-list.njk" import appActionList %}
@@ -20,8 +20,8 @@
2020
<meta name="format-detection" content="telephone=no">
2121

2222
{% set assetsName = assetsName | default("application") %}
23-
<link rel="stylesheet" href="/assets/{{ assetsName }}.css" media="all">
24-
<script src="/assets/{{ assetsName }}.js" type="module"></script>
23+
<link rel="stylesheet" href="/assets/stylesheets/{{ assetsName }}.css" media="all">
24+
<script src="/assets/javascripts/{{ assetsName }}.js" type="module"></script>
2525
{% endblock %}
2626

2727
{% block header %}
@@ -129,7 +129,7 @@
129129
}, {
130130
text: "Clear session data",
131131
href: "/clear-session-data"
132-
} if useAutoStoreData, {
132+
}, {
133133
text: "Design history",
134134
href: "https://design-history.prevention-services.nhs.uk/manage-vaccinations-in-schools/"
135135
}]

app/views/layout.html

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

lib/create-data.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import process from 'node:process'
22

33
import { faker } from '@faker-js/faker'
44
import { isSameDay } from 'date-fns'
5-
import 'dotenv/config'
65

76
import clinicsData from '../app/datasets/clinics.js'
87
import programmesData from '../app/datasets/programmes.js'

0 commit comments

Comments
 (0)