Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

.data
/node_modules
/assets
/public
57 changes: 57 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import sessionInDatabase from 'connect-pg-simple'
import express from 'express'
import session from 'express-session'
import NHSPrototypeKit from 'nhsuk-prototype-kit'
import { Pool } from 'pg'

import sessionDataDefaults from './app/data.js'
import filters from './app/filters.js'
import globals from './app/globals.js'
import routes from './app/routes.js'

const { DATABASE_URL, NODE_ENV } = process.env

const app = express()

if (DATABASE_URL) {
app.use(
session({
cookie: {
maxAge: 1000 * 60 * 60 * 4, // 4 hours
secure: process.env.NODE_ENV === 'production'
},
resave: false,
saveUninitialized: false,
secret: 'manage-vaccinations-in-schools-prototype',
store: new (sessionInDatabase(session))({
pool: new Pool({
connectionString: DATABASE_URL,
ssl: NODE_ENV === 'production' ? { rejectUnauthorized: false } : false
})
})
})
)
}

const prototype = await NHSPrototypeKit.init({
serviceName: 'Manage vaccinations in schools',
app,
Copy link
Contributor

Choose a reason for hiding this comment

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

This app will receive a second app.use(session) store 😔

I'm not quite sure how that might behave, unless it's somehow adding a different non-conflicting name to the request?

Similarly expect lots of async session weirdness:

  • We reset using req.session.data = {} not req.session.regenerate()
  • We don't wait for req.session.save() before redirecting after POST

Probably need to wait for (and help test) this new feature instead:

buildOptions: {
entryPoints: [
'app/assets/stylesheets/*.scss',
'app/assets/javascripts/*.js'
]
},
viewsPath: ['app/views', 'node_modules/nhsuk-decorated-components'],
routes,
filters,
sessionDataDefaults
})

prototype.app.set('view engine', 'njk')
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this break all the internal error views etc that use .html extensions?

Or basic things like password.html in Heroku?

I've proposed a fix in nhsuk/nhsuk-prototype-kit-package#260

But otherwise, could you add the extensions manually for now?

- response.render('dashboard')
+ response.render('dashboard.njk')


for (const [key, value] of Object.entries(globals())) {
prototype.nunjucks?.addGlobal(key, value)
}

prototype.start(2000)
Copy link
Contributor

Choose a reason for hiding this comment

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

We use this port for Browsersync now, not Express

So assuming you want to continue using http://localhost:3000

Suggested change
prototype.start(2000)
prototype.start(3000)

21 changes: 0 additions & 21 deletions app.json

This file was deleted.

4 changes: 2 additions & 2 deletions app/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const homeController = {
)
}

response.render('views/dashboard')
response.render('dashboard')
},

start(request, response) {
response.render('views/start')
response.render('start')
}
}
2 changes: 1 addition & 1 deletion app/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
* @returns {object} Filters
*/
export default (env) => {
const filters = {}
const filters = prototypeFilters

/**
* Remove border from last summary row
Expand Down
3 changes: 3 additions & 0 deletions app/globals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash'
import { decorate } from 'nhsuk-decorated-components'

import { healthQuestions } from './datasets/health-questions.js'
import {
Expand All @@ -23,6 +24,8 @@ import {
export default () => {
const globals = {}

globals.decorate = decorate

/**
* Get boolean form field items
*
Expand Down
8 changes: 4 additions & 4 deletions app/views/_layouts/default.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "rig/default.njk" %}
{% extends "prototype-kit-template.njk" %}

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

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

{% block header %}
Expand Down Expand Up @@ -129,7 +129,7 @@
}, {
text: "Clear session data",
href: "/clear-session-data"
} if useAutoStoreData, {
}, {
text: "Design history",
href: "https://design-history.prevention-services.nhs.uk/manage-vaccinations-in-schools/"
}]
Expand Down
1 change: 0 additions & 1 deletion lib/create-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import process from 'node:process'

import { faker } from '@faker-js/faker'
import { isSameDay } from 'date-fns'
import 'dotenv/config'

import clinicsData from '../app/datasets/clinics.js'
import programmesData from '../app/datasets/programmes.js'
Expand Down
Loading