-
Notifications
You must be signed in to change notification settings - Fork 1
Switch to nhsuk-prototype-kit package #178
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
base: main
Are you sure you want to change the base?
Changes from all commits
eb4f95f
6abe6d7
7f93c75
ef8b326
d7d4af5
ffd4e85
f6c06ab
e4d14d8
be88f27
d148d2d
57f3285
954edc4
69a8a0c
3bbf5fa
4215a0f
fbd0e2a
07d548b
11ba67e
675eb4b
4ec2d05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ | |
|
|
||
| .data | ||
| /node_modules | ||
| /assets | ||
| /public | ||
| 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, | ||||||
| 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') | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this break all the internal error views etc that use Or basic things like 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
This file was deleted.
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.
This
appwill receive a secondapp.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:
req.session.data = {}notreq.session.regenerate()req.session.save()before redirecting after POSTProbably need to wait for (and help test) this new feature instead:
sessionoption nhsuk/nhsuk-prototype-kit-package#220