hof 22.8.4 → 22.9.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +30 -0
- package/config/hof-defaults.js +6 -1
- package/frontend/govuk-template/govuk_template_generated.html +102 -0
- package/frontend/template-partials/views/layout.html +2 -8
- package/frontend/themes/gov-uk/styles/_cookie-banner.scss +0 -3
- package/hof-22.9.0.tgz +0 -0
- package/lib/settings.js +1 -0
- package/package/.eslintignore +1 -0
- package/package/CHANGELOG.md +232 -0
- package/package/LICENSE +21 -0
- package/package/README.md +1887 -0
- package/package/bin/hof-build +10 -0
- package/package/bin/hof-transpiler +12 -0
- package/package/build/helpers/importer.js +29 -0
- package/package/build/helpers/local.js +35 -0
- package/package/build/helpers/resolver/import.js +32 -0
- package/package/build/helpers/resolver/nearest-package-root.js +33 -0
- package/package/build/helpers/resolver/package.js +29 -0
- package/package/build/helpers/resolver.js +16 -0
- package/package/build/index.js +49 -0
- package/package/build/lib/env.js +36 -0
- package/package/build/lib/mkdir.js +9 -0
- package/package/build/lib/run.js +17 -0
- package/package/build/lib/spawn.js +18 -0
- package/package/build/tasks/browserify/compress.js +15 -0
- package/package/build/tasks/browserify/index.js +48 -0
- package/package/build/tasks/build/index.js +6 -0
- package/package/build/tasks/images/index.js +27 -0
- package/package/build/tasks/index.js +8 -0
- package/package/build/tasks/sass/index.js +67 -0
- package/package/build/tasks/translate/index.js +20 -0
- package/package/build/tasks/watch/index.js +161 -0
- package/package/components/address-lookup/default-model.js +76 -0
- package/package/components/address-lookup/defaults.js +25 -0
- package/package/components/address-lookup/index.js +251 -0
- package/package/components/address-lookup/templates/address-lookup.html +14 -0
- package/package/components/address-lookup/templates/address.html +22 -0
- package/package/components/address-lookup/templates/postcode.html +9 -0
- package/package/components/clear-session/Readme.md +46 -0
- package/package/components/clear-session/index.js +26 -0
- package/package/components/combine-and-loop-fields/Readme.md +42 -0
- package/package/components/combine-and-loop-fields/index.js +156 -0
- package/package/components/date/fields.js +16 -0
- package/package/components/date/index.js +172 -0
- package/package/components/date/templates/date.html +20 -0
- package/package/components/emailer/assets/images/govuk_logotype_email.png +0 -0
- package/package/components/emailer/assets/images/ho_crest_27px.png +0 -0
- package/package/components/emailer/assets/images/spacer.gif +0 -0
- package/package/components/emailer/email-service.js +51 -0
- package/package/components/emailer/emailer.js +53 -0
- package/package/components/emailer/index.js +74 -0
- package/package/components/emailer/transports/debug.js +74 -0
- package/package/components/emailer/transports/index.js +8 -0
- package/package/components/emailer/transports/ses.js +36 -0
- package/package/components/emailer/transports/smtp.js +26 -0
- package/package/components/emailer/transports/stub.js +5 -0
- package/package/components/emailer/views/layout.html +63 -0
- package/package/components/homeoffice-countries/index.js +22 -0
- package/package/components/index.js +13 -0
- package/package/components/notify/index.js +62 -0
- package/package/components/notify/notify.js +51 -0
- package/package/components/session-timeout-warning/index.js +67 -0
- package/package/components/summary/index.js +237 -0
- package/package/config/builder-defaults.js +45 -0
- package/package/config/component-defaults.js +13 -0
- package/package/config/hof-defaults.js +65 -0
- package/package/config/rate-limits.js +20 -0
- package/package/config/sanitisation-rules.js +32 -0
- package/package/controller/base-controller.js +296 -0
- package/package/controller/behaviour-hooks.js +51 -0
- package/package/controller/behaviour-session.js +64 -0
- package/package/controller/controller.js +258 -0
- package/package/controller/deprecate-error.js +10 -0
- package/package/controller/formatting/formatters.js +70 -0
- package/package/controller/formatting/index.js +32 -0
- package/package/controller/index.js +17 -0
- package/package/controller/validation/email.js +30 -0
- package/package/controller/validation/index.js +101 -0
- package/package/controller/validation/validators.js +181 -0
- package/package/controller/validation-error.js +14 -0
- package/package/frontend/govuk-template/build/config.js +24 -0
- package/package/frontend/govuk-template/build/govuk_template.html +102 -0
- package/package/frontend/govuk-template/build/index.js +23 -0
- package/package/frontend/govuk-template/govuk_template_generated.html +102 -0
- package/package/frontend/govuk-template/index.js +29 -0
- package/package/frontend/index.js +9 -0
- package/package/frontend/template-mixins/mixins/helpers.js +103 -0
- package/package/frontend/template-mixins/mixins/index.js +37 -0
- package/package/frontend/template-mixins/mixins/render.js +12 -0
- package/package/frontend/template-mixins/mixins/template-mixins.js +520 -0
- package/package/frontend/template-mixins/partials/forms/checkbox-group.html +47 -0
- package/package/frontend/template-mixins/partials/forms/checkbox.html +16 -0
- package/package/frontend/template-mixins/partials/forms/input-submit.html +1 -0
- package/package/frontend/template-mixins/partials/forms/input-text-date.html +37 -0
- package/package/frontend/template-mixins/partials/forms/input-text-group.html +45 -0
- package/package/frontend/template-mixins/partials/forms/option-group.html +43 -0
- package/package/frontend/template-mixins/partials/forms/select.html +17 -0
- package/package/frontend/template-mixins/partials/forms/textarea-group.html +37 -0
- package/package/frontend/template-mixins/partials/mixins/panel.html +4 -0
- package/package/frontend/template-partials/index.js +9 -0
- package/package/frontend/template-partials/translations/index.js +26 -0
- package/package/frontend/template-partials/translations/src/cy/base.json +4 -0
- package/package/frontend/template-partials/translations/src/cy/buttons.json +6 -0
- package/package/frontend/template-partials/translations/src/cy/cookies.json +104 -0
- package/package/frontend/template-partials/translations/src/cy/errorlist.json +6 -0
- package/package/frontend/template-partials/translations/src/cy/errors.json +18 -0
- package/package/frontend/template-partials/translations/src/cy/terms.json +28 -0
- package/package/frontend/template-partials/translations/src/en/accessibility.json +43 -0
- package/package/frontend/template-partials/translations/src/en/base.json +5 -0
- package/package/frontend/template-partials/translations/src/en/buttons.json +10 -0
- package/package/frontend/template-partials/translations/src/en/cookies.json +116 -0
- package/package/frontend/template-partials/translations/src/en/errorlist.json +7 -0
- package/package/frontend/template-partials/translations/src/en/errors.json +35 -0
- package/package/frontend/template-partials/translations/src/en/exit.json +5 -0
- package/package/frontend/template-partials/translations/src/en/fields.json +5 -0
- package/package/frontend/template-partials/translations/src/en/journey.json +6 -0
- package/package/frontend/template-partials/translations/src/en/save-and-exit.json +4 -0
- package/package/frontend/template-partials/translations/src/en/terms.json +28 -0
- package/package/frontend/template-partials/views/404.html +9 -0
- package/package/frontend/template-partials/views/accessibility.html +55 -0
- package/package/frontend/template-partials/views/confirm.html +8 -0
- package/package/frontend/template-partials/views/confirmation.html +19 -0
- package/package/frontend/template-partials/views/content/en/what-happens-next.md +0 -0
- package/package/frontend/template-partials/views/cookie-error.html +1 -0
- package/package/frontend/template-partials/views/cookies.html +84 -0
- package/package/frontend/template-partials/views/email/data-row.html +4 -0
- package/package/frontend/template-partials/views/email/formatted.html +12 -0
- package/package/frontend/template-partials/views/email/layout.html +63 -0
- package/package/frontend/template-partials/views/email/raw.html +11 -0
- package/package/frontend/template-partials/views/email/section-row.html +3 -0
- package/package/frontend/template-partials/views/error.html +20 -0
- package/package/frontend/template-partials/views/exit.html +9 -0
- package/package/frontend/template-partials/views/feedback-submitted.html +11 -0
- package/package/frontend/template-partials/views/layout.html +55 -0
- package/package/frontend/template-partials/views/partials/analytics-table.html +25 -0
- package/package/frontend/template-partials/views/partials/back.html +5 -0
- package/package/frontend/template-partials/views/partials/bullet-list.html +7 -0
- package/package/frontend/template-partials/views/partials/confirmation-alert.html +6 -0
- package/package/frontend/template-partials/views/partials/continue.html +5 -0
- package/package/frontend/template-partials/views/partials/cookie-banner.html +29 -0
- package/package/frontend/template-partials/views/partials/cookie-notification.html +4 -0
- package/package/frontend/template-partials/views/partials/cookie-settings-button.html +1 -0
- package/package/frontend/template-partials/views/partials/cookie-settings-radio.html +8 -0
- package/package/frontend/template-partials/views/partials/details-summary.html +8 -0
- package/package/frontend/template-partials/views/partials/external-link.html +1 -0
- package/package/frontend/template-partials/views/partials/form.html +10 -0
- package/package/frontend/template-partials/views/partials/gatag.html +60 -0
- package/package/frontend/template-partials/views/partials/head.html +31 -0
- package/package/frontend/template-partials/views/partials/heading.html +11 -0
- package/package/frontend/template-partials/views/partials/items-table.html +32 -0
- package/package/frontend/template-partials/views/partials/maincontent-left.html +10 -0
- package/package/frontend/template-partials/views/partials/navigation.html +8 -0
- package/package/frontend/template-partials/views/partials/page.html +23 -0
- package/package/frontend/template-partials/views/partials/panel-indent.html +3 -0
- package/package/frontend/template-partials/views/partials/session-cookies-table.html +28 -0
- package/package/frontend/template-partials/views/partials/session-timeout-warning.html +38 -0
- package/package/frontend/template-partials/views/partials/summary-table-row.html +14 -0
- package/package/frontend/template-partials/views/partials/summary-table.html +8 -0
- package/package/frontend/template-partials/views/partials/table.html +18 -0
- package/package/frontend/template-partials/views/partials/validation-list.html +3 -0
- package/package/frontend/template-partials/views/partials/validation-summary.html +25 -0
- package/package/frontend/template-partials/views/partials/warn.html +7 -0
- package/package/frontend/template-partials/views/rate-limit-error.html +10 -0
- package/package/frontend/template-partials/views/save-and-exit.html +17 -0
- package/package/frontend/template-partials/views/service-unavailable.html +13 -0
- package/package/frontend/template-partials/views/session-timeout.html +7 -0
- package/package/frontend/template-partials/views/step.html +14 -0
- package/package/frontend/template-partials/views/terms.html +26 -0
- package/package/frontend/themes/gov-uk/client-js/cookieSettings.js +145 -0
- package/package/frontend/themes/gov-uk/client-js/govuk-cookies.js +121 -0
- package/package/frontend/themes/gov-uk/client-js/index.js +27 -0
- package/package/frontend/themes/gov-uk/client-js/session-timeout-dialog.js +348 -0
- package/package/frontend/themes/gov-uk/client-js/skip-to-main.js +19 -0
- package/package/frontend/themes/gov-uk/index.js +9 -0
- package/package/frontend/themes/gov-uk/styles/_base.scss +17 -0
- package/package/frontend/themes/gov-uk/styles/_check_your_answers.scss +155 -0
- package/package/frontend/themes/gov-uk/styles/_cookie-banner.scss +111 -0
- package/package/frontend/themes/gov-uk/styles/_cookie-settings.scss +33 -0
- package/package/frontend/themes/gov-uk/styles/_govuk_frontend_toolkit.scss +23 -0
- package/package/frontend/themes/gov-uk/styles/_helpers.scss +5 -0
- package/package/frontend/themes/gov-uk/styles/_layout.scss +125 -0
- package/package/frontend/themes/gov-uk/styles/_panel-indent.scss +27 -0
- package/package/frontend/themes/gov-uk/styles/_pdf.scss +42 -0
- package/package/frontend/themes/gov-uk/styles/_session-timeout-dialog.scss +121 -0
- package/package/frontend/themes/gov-uk/styles/_typography.scss +27 -0
- package/package/frontend/themes/gov-uk/styles/_variables.scss +11 -0
- package/package/frontend/themes/gov-uk/styles/govuk.scss +43 -0
- package/package/frontend/themes/gov-uk/styles/mixins.scss +16 -0
- package/package/frontend/themes/gov-uk/styles/modules/_alerts.scss +73 -0
- package/package/frontend/themes/gov-uk/styles/modules/_buttons.scss +5 -0
- package/package/frontend/themes/gov-uk/styles/modules/_character-count.scss +8 -0
- package/package/frontend/themes/gov-uk/styles/modules/_confirm-page.scss +20 -0
- package/package/frontend/themes/gov-uk/styles/modules/_lists.scss +5 -0
- package/package/frontend/themes/gov-uk/styles/modules/_progressive-reveal.scss +17 -0
- package/package/frontend/themes/gov-uk/styles/modules/_validation.scss +51 -0
- package/package/frontend/themes/index.js +5 -0
- package/package/frontend/toolkit/assets/images/passports/new-window-link-blue.png +0 -0
- package/package/frontend/toolkit/assets/images/passports/new-window-link.png +0 -0
- package/package/frontend/toolkit/assets/images/spinner.gif +0 -0
- package/package/frontend/toolkit/assets/javascript/character-count.js +99 -0
- package/package/frontend/toolkit/assets/javascript/form-focus.js +101 -0
- package/package/frontend/toolkit/assets/javascript/helpers.js +177 -0
- package/package/frontend/toolkit/assets/javascript/progressive-reveal.js +72 -0
- package/package/frontend/toolkit/assets/javascript/validation.js +71 -0
- package/package/frontend/toolkit/assets/javascript/vendor/details.polyfill.js +189 -0
- package/package/frontend/toolkit/assets/javascript/vendor/indexof.polyfill.js +39 -0
- package/package/frontend/toolkit/assets/javascript/vendor/safari-cachebuster.js +6 -0
- package/package/frontend/toolkit/assets/stylesheets/_base.scss +17 -0
- package/package/frontend/toolkit/assets/stylesheets/_helpers.scss +5 -0
- package/package/frontend/toolkit/assets/stylesheets/_layout.scss +118 -0
- package/package/frontend/toolkit/assets/stylesheets/_typography.scss +27 -0
- package/package/frontend/toolkit/assets/stylesheets/_variables.scss +11 -0
- package/package/frontend/toolkit/assets/stylesheets/app.scss +30 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_buttons.scss +47 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_details.scss +38 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_elements-typography.scss +175 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_forms.scss +167 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_helpers.scss +39 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_layout.scss +67 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_lists.scss +40 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_panels.scss +29 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_reset.scss +33 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_tables.scss +33 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-block-labels.scss +63 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-date.scss +39 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-validation.scss +63 -0
- package/package/frontend/toolkit/assets/stylesheets/mixins.scss +16 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_alerts.scss +73 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_buttons.scss +5 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_confirm-page.scss +20 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_lists.scss +5 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_progressive-reveal.scss +17 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_validation.scss +51 -0
- package/package/frontend/toolkit/index.js +10 -0
- package/package/index.js +351 -0
- package/package/lib/deindex.js +18 -0
- package/package/lib/encryption.js +23 -0
- package/package/lib/ga-tag.js +89 -0
- package/package/lib/health.js +26 -0
- package/package/lib/helpers.js +66 -0
- package/package/lib/logger.js +65 -0
- package/package/lib/markdown.js +46 -0
- package/package/lib/router.js +111 -0
- package/package/lib/serve-static.js +12 -0
- package/package/lib/sessions.js +82 -0
- package/package/lib/settings.js +74 -0
- package/package/lib/which.js +28 -0
- package/package/middleware/cookies.js +43 -0
- package/package/middleware/deep-translate.js +32 -0
- package/package/middleware/errors.js +119 -0
- package/package/middleware/index.js +10 -0
- package/package/middleware/not-found.js +38 -0
- package/package/middleware/rate-limiter.js +98 -0
- package/package/middleware/service-unavailable.js +64 -0
- package/package/model/apis/axios-settings.js +21 -0
- package/package/model/apis/html-to-pdf-converter.js +35 -0
- package/package/model/apis/index.js +5 -0
- package/package/model/index.js +348 -0
- package/package/package.json +147 -0
- package/package/sandbox/README.md +66 -0
- package/package/sandbox/apps/sandbox/behaviours/clear-session.js +8 -0
- package/package/sandbox/apps/sandbox/behaviours/country-select.js +10 -0
- package/package/sandbox/apps/sandbox/behaviours/international-number.js +22 -0
- package/package/sandbox/apps/sandbox/fields.js +128 -0
- package/package/sandbox/apps/sandbox/index.js +99 -0
- package/package/sandbox/apps/sandbox/lib/staticAppealStages.js +189 -0
- package/package/sandbox/apps/sandbox/sections/summary-data-sections.js +43 -0
- package/package/sandbox/apps/sandbox/translations/src/en/errors.json +5 -0
- package/package/sandbox/apps/sandbox/translations/src/en/exit.json +4 -0
- package/package/sandbox/apps/sandbox/translations/src/en/fields.json +101 -0
- package/package/sandbox/apps/sandbox/translations/src/en/journey.json +7 -0
- package/package/sandbox/apps/sandbox/translations/src/en/pages.json +72 -0
- package/package/sandbox/apps/sandbox/translations/src/en/validation.json +54 -0
- package/package/sandbox/apps/sandbox/views/form-guidance-link.html +8 -0
- package/package/sandbox/apps/sandbox/views/save-and-exit.html +19 -0
- package/package/sandbox/assets/images/icons/icon-caret-left.png +0 -0
- package/package/sandbox/assets/images/icons/icon-complete.png +0 -0
- package/package/sandbox/assets/images/icons/icon-cross-remove-sign.png +0 -0
- package/package/sandbox/assets/js/index.js +70 -0
- package/package/sandbox/assets/scss/app.scss +27 -0
- package/package/sandbox/codecept.conf.js +15 -0
- package/package/sandbox/config.js +17 -0
- package/package/sandbox/package.json +26 -0
- package/package/sandbox/server.js +23 -0
- package/package/sandbox/yarn.lock +262 -0
- package/package/transpiler/index.js +2 -0
- package/package/transpiler/lib/aggregate.js +32 -0
- package/package/transpiler/lib/build.js +15 -0
- package/package/transpiler/lib/compile.js +12 -0
- package/package/transpiler/lib/expand-dirs.js +14 -0
- package/package/transpiler/lib/write-files.js +24 -0
- package/package/utilities/autofill/index.js +189 -0
- package/package/utilities/autofill/inputs.js +60 -0
- package/package/utilities/countries.js +12 -0
- package/package/utilities/helpers/index.js +189 -0
- package/package/utilities/index.js +9 -0
- package/package/utilities/reqres/index.js +18 -0
- package/package/utilities/test-data/data/domain.json +7 -0
- package/package/utilities/test-data/data/firstname.json +16 -0
- package/package/utilities/test-data/data/lastname.json +10 -0
- package/package/utilities/test-data/data/postcode.json +12 -0
- package/package/utilities/test-data/data/streetname.json +8 -0
- package/package/utilities/test-data/data/streetsuffix.json +7 -0
- package/package/utilities/test-data/data/town.json +9 -0
- package/package/utilities/test-data/index.js +67 -0
- package/package/wizard/behaviours/complete.js +20 -0
- package/package/wizard/behaviours/index.js +5 -0
- package/package/wizard/index.js +124 -0
- package/package/wizard/middleware/back-links.js +68 -0
- package/package/wizard/middleware/check-complete.js +13 -0
- package/package/wizard/middleware/check-progress.js +139 -0
- package/package/wizard/middleware/check-session.js +17 -0
- package/package/wizard/middleware/csrf.js +47 -0
- package/package/wizard/middleware/session-model.js +11 -0
- package/package/wizard/middleware/session.js +9 -0
- package/package/wizard/model.js +29 -0
- package/package/wizard/util/constants.js +5 -0
- package/package/wizard/util/helpers.js +19 -0
- package/package.json +5 -6
- package/.editorconfig +0 -10
- package/.github/workflows/automate-publish.yml +0 -38
- package/.github/workflows/automate-tag.yml +0 -78
- package/.istanbul.yml +0 -20
- package/codeReviewChecklist.md +0 -22
- package/pull_request_template.md +0 -16
@@ -0,0 +1,65 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const winston = require('winston');
|
4
|
+
const { createLogger, format, transports } = winston;
|
5
|
+
const { combine, timestamp, colorize, simple, json } = format;
|
6
|
+
const util = require('util');
|
7
|
+
|
8
|
+
module.exports = config => {
|
9
|
+
const loggingTransports = [];
|
10
|
+
const exceptionTransports = [];
|
11
|
+
const notProd = config.env !== 'production';
|
12
|
+
const isLocal = notProd && config.env !== 'development';
|
13
|
+
|
14
|
+
loggingTransports.push(
|
15
|
+
new transports.Console({
|
16
|
+
format: isLocal ? combine(
|
17
|
+
colorize(),
|
18
|
+
simple()
|
19
|
+
) : json(),
|
20
|
+
silent: config.loglevel === 'silent' || config.env === 'test',
|
21
|
+
level: config.loglevel || 'info'
|
22
|
+
})
|
23
|
+
);
|
24
|
+
|
25
|
+
exceptionTransports.push(
|
26
|
+
new transports.Console({
|
27
|
+
format: isLocal ? combine(
|
28
|
+
colorize(),
|
29
|
+
simple()
|
30
|
+
) : json()
|
31
|
+
})
|
32
|
+
);
|
33
|
+
|
34
|
+
const loggerConfig = {
|
35
|
+
format: combine(
|
36
|
+
timestamp()
|
37
|
+
),
|
38
|
+
exitOnError: false,
|
39
|
+
transports: loggingTransports,
|
40
|
+
exceptionHandlers: exceptionTransports
|
41
|
+
};
|
42
|
+
|
43
|
+
if (notProd) {
|
44
|
+
delete loggerConfig.exceptionHandlers;
|
45
|
+
}
|
46
|
+
|
47
|
+
const logger = createLogger(loggerConfig);
|
48
|
+
|
49
|
+
logger.stream = {
|
50
|
+
write: message => {
|
51
|
+
if (config.loglevel === 'debug') {
|
52
|
+
logger.debug(message);
|
53
|
+
} else {
|
54
|
+
logger.info(message);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
logger.logSession = id => (level, ...args) => {
|
60
|
+
const msg = util.format(...args);
|
61
|
+
return logger.log(level, `sessionId=${id} ${msg}`);
|
62
|
+
};
|
63
|
+
|
64
|
+
return logger;
|
65
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const MarkdownIt = require('markdown-it');
|
4
|
+
const converter = new MarkdownIt({html: true});
|
5
|
+
|
6
|
+
const path = require('path');
|
7
|
+
const fs = require('fs');
|
8
|
+
const _ = require('lodash');
|
9
|
+
|
10
|
+
const cache = {};
|
11
|
+
|
12
|
+
module.exports = conf => {
|
13
|
+
const config = conf || {};
|
14
|
+
config.dir = config.dir || 'content';
|
15
|
+
config.method = config.method || 'markdown';
|
16
|
+
config.fallbackLang = config.fallbackLang || ['en', ''];
|
17
|
+
config.ext = config.ext || 'md';
|
18
|
+
return (req, res, next) => {
|
19
|
+
const View = req.app.get('view');
|
20
|
+
res.locals[config.method] = () => file => {
|
21
|
+
if (!file) {
|
22
|
+
throw new Error('markdown: filename must be specified');
|
23
|
+
}
|
24
|
+
const views = req.app.get('views');
|
25
|
+
const languages = _.uniq([].concat(req.lang).concat(config.fallbackLang)).filter(a => typeof a === 'string');
|
26
|
+
const paths = views.map(dir => languages.map(lang => path.resolve(dir, config.dir, lang.toLowerCase())));
|
27
|
+
|
28
|
+
// use express' `View` class to shortcut looking up files
|
29
|
+
const view = new View(file, {
|
30
|
+
defaultEngine: config.ext,
|
31
|
+
root: _.flatten(paths),
|
32
|
+
engines: { [`.${config.ext}`]: {} }
|
33
|
+
});
|
34
|
+
|
35
|
+
if (!view.path) {
|
36
|
+
throw new Error(`Could not find content: ${file}`);
|
37
|
+
}
|
38
|
+
|
39
|
+
const md = cache[view.path] || fs.readFileSync(view.path).toString('utf8');
|
40
|
+
cache[view.path] = md;
|
41
|
+
|
42
|
+
return converter.render(md);
|
43
|
+
};
|
44
|
+
next();
|
45
|
+
};
|
46
|
+
};
|
@@ -0,0 +1,111 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _ = require('lodash');
|
4
|
+
const express = require('express');
|
5
|
+
const wizard = require('../wizard');
|
6
|
+
const translate = require('i18n-future').middleware;
|
7
|
+
const deepTranslate = require('../middleware').deepTranslate;
|
8
|
+
const expressPartialTemplates = require('express-partial-templates');
|
9
|
+
const helpers = require('./helpers');
|
10
|
+
const deprecate = require('deprecate');
|
11
|
+
|
12
|
+
function applyBehaviours(steps, behaviours) {
|
13
|
+
_.each(steps, step => {
|
14
|
+
step.behaviours = [].concat(behaviours).concat(step.behaviours).filter(a => a);
|
15
|
+
});
|
16
|
+
}
|
17
|
+
|
18
|
+
function getWizardConfig(config) {
|
19
|
+
const wizardConfig = {
|
20
|
+
name: config.route.name || (config.route.baseUrl || '').replace('/', ''),
|
21
|
+
protocol: config.protocol,
|
22
|
+
env: config.env,
|
23
|
+
sanitiseInputs: config.sanitiseInputs
|
24
|
+
};
|
25
|
+
|
26
|
+
if (config.appConfig) {
|
27
|
+
wizardConfig.appConfig = config.appConfig;
|
28
|
+
}
|
29
|
+
|
30
|
+
// whitelist properties from the route's config that should be passed into the form wizard
|
31
|
+
const props = [
|
32
|
+
'confirmStep',
|
33
|
+
'exitStep',
|
34
|
+
'saveAndExitStep',
|
35
|
+
'params'
|
36
|
+
];
|
37
|
+
Object.assign(wizardConfig, _.pick(config.route, props));
|
38
|
+
|
39
|
+
return wizardConfig;
|
40
|
+
}
|
41
|
+
|
42
|
+
const returnBaseUrl = (url = '') => {
|
43
|
+
const splitUrl = url.split('/');
|
44
|
+
|
45
|
+
return splitUrl.length > 2 ? `/${splitUrl[1]}` : '/';
|
46
|
+
};
|
47
|
+
|
48
|
+
module.exports = config => {
|
49
|
+
const app = express();
|
50
|
+
const paths = helpers.getPaths(config);
|
51
|
+
const fields = helpers.getFields(paths.fields);
|
52
|
+
const routeViews = helpers.getViews(paths.views, config.route.views);
|
53
|
+
const sharedViews = config.sharedViews;
|
54
|
+
|
55
|
+
const views = routeViews ? [routeViews].concat(sharedViews) : sharedViews;
|
56
|
+
|
57
|
+
app.set('x-powered-by', false);
|
58
|
+
app.set('view engine', config.viewEngine);
|
59
|
+
app.set('views', views);
|
60
|
+
|
61
|
+
app.use(expressPartialTemplates(app));
|
62
|
+
|
63
|
+
app.use(translate({
|
64
|
+
resources: config.theme.translations,
|
65
|
+
path: paths.translations + '/__lng__/__ns__.json'
|
66
|
+
}));
|
67
|
+
app.use(deepTranslate());
|
68
|
+
|
69
|
+
const wizardConfig = getWizardConfig(config);
|
70
|
+
|
71
|
+
if (config.baseController) {
|
72
|
+
deprecate(
|
73
|
+
'`baseController` option is deprecated and may be removed in future versions.',
|
74
|
+
'Use `behaviours` option to define global behaviours.'
|
75
|
+
);
|
76
|
+
wizardConfig.controller = config.baseController;
|
77
|
+
}
|
78
|
+
|
79
|
+
if (config.route.behaviours) {
|
80
|
+
applyBehaviours(config.route.steps, config.route.behaviours);
|
81
|
+
}
|
82
|
+
|
83
|
+
if (config.behaviours) {
|
84
|
+
applyBehaviours(config.route.steps, config.behaviours);
|
85
|
+
}
|
86
|
+
|
87
|
+
Object.keys(config.route.pages || {}).forEach(path => {
|
88
|
+
app.get(path, (req, res) => {
|
89
|
+
let objPath = config.route.pages[path];
|
90
|
+
|
91
|
+
if (typeof objPath === 'string') {
|
92
|
+
objPath = {
|
93
|
+
template: objPath,
|
94
|
+
title: objPath
|
95
|
+
};
|
96
|
+
}
|
97
|
+
res.locals = Object.assign(res.locals, {
|
98
|
+
baseUrl: returnBaseUrl(req.originalUrl),
|
99
|
+
refererUrl: req.headers.referer,
|
100
|
+
title: objPath.title
|
101
|
+
});
|
102
|
+
return res.render(objPath.template);
|
103
|
+
});
|
104
|
+
});
|
105
|
+
|
106
|
+
if (config.route.steps) {
|
107
|
+
app.use(wizard(config.route.steps, fields, wizardConfig));
|
108
|
+
}
|
109
|
+
|
110
|
+
return app;
|
111
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const express = require('express');
|
4
|
+
const path = require('path');
|
5
|
+
|
6
|
+
module.exports = (app, config) => {
|
7
|
+
if (config.serveStatic !== false) {
|
8
|
+
app.use('/public', express.static(path.resolve(config.root, 'public')));
|
9
|
+
}
|
10
|
+
|
11
|
+
return app;
|
12
|
+
};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const redis = require('redis');
|
4
|
+
const session = require('express-session');
|
5
|
+
const connectRedis = require('connect-redis');
|
6
|
+
const cookieParser = require('cookie-parser');
|
7
|
+
|
8
|
+
const secureHttps = config => config.protocol === 'https' || config.env === 'production';
|
9
|
+
|
10
|
+
module.exports = (app, config) => {
|
11
|
+
const logger = config.logger || console;
|
12
|
+
|
13
|
+
if (config.env === 'production' && config.session.secret === 'changethis') {
|
14
|
+
throw new Error('Session secret must be set to a unique random string for production environments');
|
15
|
+
}
|
16
|
+
|
17
|
+
app.use(cookieParser(config.session.secret, {
|
18
|
+
path: '/',
|
19
|
+
httpOnly: true,
|
20
|
+
secure: secureHttps(config)
|
21
|
+
}));
|
22
|
+
|
23
|
+
if (config.sessionStore) {
|
24
|
+
return app.use(session({
|
25
|
+
store: config.sessionStore,
|
26
|
+
genid: () => 'fakeId',
|
27
|
+
saveUninitialized: true,
|
28
|
+
resave: false
|
29
|
+
}));
|
30
|
+
}
|
31
|
+
|
32
|
+
const encryption = require('./encryption')(config.session.secret);
|
33
|
+
const RedisStore = connectRedis(session);
|
34
|
+
const client = redis.createClient(config.redis);
|
35
|
+
|
36
|
+
if (config.env !== 'test') {
|
37
|
+
client.on('connecting', () => {
|
38
|
+
logger.info('Connecting to redis');
|
39
|
+
});
|
40
|
+
|
41
|
+
client.on('connect', () => {
|
42
|
+
logger.info('Connected to redis');
|
43
|
+
});
|
44
|
+
|
45
|
+
client.on('reconnecting', () => {
|
46
|
+
logger.info('Reconnecting to redis');
|
47
|
+
});
|
48
|
+
|
49
|
+
client.on('error', e => {
|
50
|
+
logger.error(e);
|
51
|
+
});
|
52
|
+
}
|
53
|
+
|
54
|
+
const store = new RedisStore({
|
55
|
+
client: client,
|
56
|
+
ttl: config.session.ttl,
|
57
|
+
secret: config.session.secret,
|
58
|
+
serializer: {
|
59
|
+
parse: data => JSON.parse(encryption.decrypt(data)),
|
60
|
+
stringify: data => encryption.encrypt(JSON.stringify(data))
|
61
|
+
}
|
62
|
+
});
|
63
|
+
|
64
|
+
app.set('trust proxy', true);
|
65
|
+
|
66
|
+
const sessionOpts = Object.assign({
|
67
|
+
store,
|
68
|
+
name: config.session.name,
|
69
|
+
cookie: {
|
70
|
+
secure: secureHttps(config),
|
71
|
+
sameSite: config.cookie?.sameSite === 'lax' ? config.cookie?.sameSite : 'strict',
|
72
|
+
httpOnly: true
|
73
|
+
},
|
74
|
+
secret: config.session.secret,
|
75
|
+
saveUninitialized: true,
|
76
|
+
resave: true
|
77
|
+
}, config.session);
|
78
|
+
|
79
|
+
app.use(session(sessionOpts));
|
80
|
+
|
81
|
+
return client;
|
82
|
+
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _ = require('lodash');
|
4
|
+
const fs = require('fs');
|
5
|
+
const path = require('path');
|
6
|
+
const hoganExpressStrict = require('hogan-express-strict');
|
7
|
+
const expressPartialTemplates = require('express-partial-templates');
|
8
|
+
const bodyParser = require('body-parser');
|
9
|
+
|
10
|
+
const dirExists = dir => {
|
11
|
+
try {
|
12
|
+
if (fs.existsSync(dir)) {
|
13
|
+
return true;
|
14
|
+
}
|
15
|
+
return false;
|
16
|
+
} catch(err) {
|
17
|
+
throw new Error(`${err}: Cannot check if the directory path exists`);
|
18
|
+
}
|
19
|
+
};
|
20
|
+
|
21
|
+
const filterEmptyViews = views => {
|
22
|
+
return views.filter(view => dirExists(view));
|
23
|
+
};
|
24
|
+
|
25
|
+
module.exports = async (app, config) => {
|
26
|
+
const viewEngine = config.viewEngine || 'html';
|
27
|
+
|
28
|
+
app.use((req, res, next) => {
|
29
|
+
res.locals.assetPath = '/public';
|
30
|
+
next();
|
31
|
+
});
|
32
|
+
|
33
|
+
app.use(config.theme());
|
34
|
+
|
35
|
+
const filteredViews = filterEmptyViews(config.theme.views);
|
36
|
+
const viewPaths = [].concat(filteredViews);
|
37
|
+
app.set('view engine', viewEngine);
|
38
|
+
app.enable('view cache');
|
39
|
+
|
40
|
+
if (config.views) {
|
41
|
+
const viewsArray = _.castArray(config.views);
|
42
|
+
viewsArray.slice().reverse().forEach(view => {
|
43
|
+
const customViewPath = path.resolve(config.root, view);
|
44
|
+
try {
|
45
|
+
fs.accessSync(customViewPath, fs.F_OK);
|
46
|
+
} catch (err) {
|
47
|
+
throw new Error(`Cannot find views at ${customViewPath}`);
|
48
|
+
}
|
49
|
+
viewPaths.unshift(customViewPath);
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
app.set('views', viewPaths);
|
54
|
+
app.use(expressPartialTemplates(app));
|
55
|
+
|
56
|
+
app.engine(viewEngine, hoganExpressStrict);
|
57
|
+
|
58
|
+
app.use(bodyParser.urlencoded({
|
59
|
+
extended: true
|
60
|
+
}));
|
61
|
+
|
62
|
+
app.use(bodyParser.json());
|
63
|
+
|
64
|
+
app.use((req, res, next) => {
|
65
|
+
res.locals.baseUrl = req.baseUrl;
|
66
|
+
res.locals.showCookiesBanner = config.showCookiesBanner;
|
67
|
+
next();
|
68
|
+
});
|
69
|
+
|
70
|
+
// Trust proxy for secure cookies
|
71
|
+
app.set('trust proxy', 1);
|
72
|
+
|
73
|
+
return app;
|
74
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const path = require('path');
|
4
|
+
const stack = require('callsite');
|
5
|
+
const findup = require('findup');
|
6
|
+
|
7
|
+
function which(name, scpt) {
|
8
|
+
if (!name) { throw new Error('package name must be provided'); }
|
9
|
+
const script = scpt || name;
|
10
|
+
|
11
|
+
const pkgPath = `node_modules/${name}/package.json`;
|
12
|
+
const callsite = stack()[1].getFileName();
|
13
|
+
const dir = findup.sync(callsite, pkgPath);
|
14
|
+
|
15
|
+
const pkgLocation = path.join(dir, pkgPath);
|
16
|
+
const pkg = require(pkgLocation);
|
17
|
+
let bin = pkg.bin[script];
|
18
|
+
|
19
|
+
if (!bin && typeof pkg.bin === 'string') {
|
20
|
+
bin = pkg.bin;
|
21
|
+
}
|
22
|
+
|
23
|
+
if (!bin) { throw new Error(`binary path for ${script} not found`); }
|
24
|
+
|
25
|
+
return path.resolve(path.dirname(pkgLocation), bin);
|
26
|
+
}
|
27
|
+
|
28
|
+
module.exports = which;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const URI = require('urijs');
|
4
|
+
|
5
|
+
const isHealthcheckUrl = (path, healthcheckUrls) => healthcheckUrls.some(url => path.includes(url));
|
6
|
+
const secureHttps = config => config.protocol === 'https' || config.env === 'production';
|
7
|
+
|
8
|
+
module.exports = options => {
|
9
|
+
const checkName = 'hof-cookie-check';
|
10
|
+
const cookieName = (options || {})['cookie-name'] || checkName;
|
11
|
+
const paramName = (options || {})['param-name'] || checkName;
|
12
|
+
let healthcheckUrls;
|
13
|
+
|
14
|
+
if (options && options.healthcheckUrls) {
|
15
|
+
healthcheckUrls = options.healthcheckUrls;
|
16
|
+
} else {
|
17
|
+
healthcheckUrls = ['/healthz', '/livez', '/readyz'];
|
18
|
+
}
|
19
|
+
|
20
|
+
return (req, res, next) => {
|
21
|
+
const reqIncludesCookies = req.cookies && Object.keys(req.cookies).length;
|
22
|
+
const reqIsCookieCheckRedirect = req.query[paramName] !== undefined;
|
23
|
+
|
24
|
+
if (reqIncludesCookies || isHealthcheckUrl(req.path, healthcheckUrls)) {
|
25
|
+
const prefs = 'cookie_preferences' in req.cookies ? JSON.parse(req.cookies.cookie_preferences) : {};
|
26
|
+
res.locals.cookiesAccepted = Boolean(prefs.usage);
|
27
|
+
next();
|
28
|
+
} else if (req.cookies === undefined || (!Object.keys(req.cookies).length && reqIsCookieCheckRedirect)) {
|
29
|
+
const err = new Error('Cookies required');
|
30
|
+
err.code = 'NO_COOKIES';
|
31
|
+
next(err, req, res, next);
|
32
|
+
} else {
|
33
|
+
// Set samesite to lax to allow setting cookies on redirects from Gov.UK
|
34
|
+
res.cookie(cookieName, 1, { sameSite: 'lax', secure: secureHttps(options), httpOnly: true });
|
35
|
+
|
36
|
+
const uriClean = req.originalUrl && req.originalUrl.match(/^\/[^\/\\]/);
|
37
|
+
const uriToRedirect = uriClean ? req.originalUrl : '/';
|
38
|
+
const redirectURL = new URI(uriToRedirect).addQuery(encodeURIComponent(paramName));
|
39
|
+
|
40
|
+
res.redirect(redirectURL.toString());
|
41
|
+
}
|
42
|
+
};
|
43
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _ = require('lodash');
|
4
|
+
|
5
|
+
const Translator = (translate, req) => function deepTranslate(key) {
|
6
|
+
let translated = translate(key);
|
7
|
+
if (_.isPlainObject(translated)) {
|
8
|
+
translated = _.reduceRight(translated, (prev, item, tKey) => {
|
9
|
+
let translationPath = key + '.' + tKey;
|
10
|
+
if (_.isPlainObject(item) && req.sessionModel) {
|
11
|
+
let value = req.sessionModel.get(tKey);
|
12
|
+
if (value) {
|
13
|
+
value = value.toString();
|
14
|
+
}
|
15
|
+
translationPath += '.' + value;
|
16
|
+
}
|
17
|
+
const result = deepTranslate(translationPath);
|
18
|
+
return result !== translationPath ? result : prev;
|
19
|
+
}, '');
|
20
|
+
}
|
21
|
+
return translated;
|
22
|
+
};
|
23
|
+
|
24
|
+
module.exports = opts => {
|
25
|
+
const options = opts || {};
|
26
|
+
return (req, res, next) => {
|
27
|
+
const translate = options.translate || req.translate || (a => a);
|
28
|
+
req.translate = Translator(translate, req);
|
29
|
+
req.rawTranslate = translate;
|
30
|
+
next();
|
31
|
+
};
|
32
|
+
};
|
@@ -0,0 +1,119 @@
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const rateLimitsConfig = require('../config/rate-limits');
|
5
|
+
|
6
|
+
const errorTitle = code => `${code}_ERROR`;
|
7
|
+
const errorMsg = code => `There is a ${code}_ERROR`;
|
8
|
+
|
9
|
+
// eslint-disable-next-line complexity
|
10
|
+
const getContent = (err, translate) => {
|
11
|
+
const content = {};
|
12
|
+
|
13
|
+
// Helper to safely call translate if it's a function
|
14
|
+
const t = key => (typeof translate === 'function' ? translate(key) : undefined);
|
15
|
+
|
16
|
+
if (err.code === 'SESSION_TIMEOUT') {
|
17
|
+
err.status = 401;
|
18
|
+
err.template = 'session-timeout';
|
19
|
+
err.serviceName = t('journey.serviceName') || t('journey.header');
|
20
|
+
err.title = t('errors.session.title');
|
21
|
+
err.message = t('errors.session.message');
|
22
|
+
content.serviceName = t('journey.serviceName') || t('journey.header');
|
23
|
+
content.title = t('errors.session.title');
|
24
|
+
content.message = t('errors.session.message');
|
25
|
+
}
|
26
|
+
|
27
|
+
if (err.code === 'NO_COOKIES') {
|
28
|
+
err.status = 403;
|
29
|
+
err.template = 'cookie-error';
|
30
|
+
content.serviceName = t('journey.serviceName') || t('journey.header');
|
31
|
+
content.title = t('errors.cookies-required.title');
|
32
|
+
content.message = t('errors.cookies-required.message');
|
33
|
+
}
|
34
|
+
|
35
|
+
if (err.code === 'DDOS_RATE_LIMIT') {
|
36
|
+
err.status = 429;
|
37
|
+
err.template = 'rate-limit-error';
|
38
|
+
err.serviceName = t('journey.serviceName') || t('journey.header');
|
39
|
+
err.title = t('errors.ddos-rate-limit.title');
|
40
|
+
err.message = t('errors.ddos-rate-limit.message');
|
41
|
+
err.preTimeToWait = t('errors.ddos-rate-limit.pre-time-to-wait');
|
42
|
+
err.timeToWait = rateLimitsConfig.rateLimits.requests.windowSizeInMinutes;
|
43
|
+
err.postTimeToWait = t('errors.ddos-rate-limit.post-time-to-wait');
|
44
|
+
content.title = t('errors.ddos-rate-limit.title');
|
45
|
+
content.serviceName = t('journey.serviceName') || t('journey.header');
|
46
|
+
content.message = t('errors.ddos-rate-limit.message');
|
47
|
+
content.preTimeToWait = t('errors.ddos-rate-limit.pre-time-to-wait');
|
48
|
+
content.timeToWait = rateLimitsConfig.rateLimits.requests.windowSizeInMinutes;
|
49
|
+
content.postTimeToWait = t('errors.ddos-rate-limit.post-time-to-wait');
|
50
|
+
}
|
51
|
+
|
52
|
+
if (err.code === 'SUBMISSION_RATE_LIMIT') {
|
53
|
+
err.status = 429;
|
54
|
+
err.template = 'rate-limit-error';
|
55
|
+
err.serviceName = t('journey.serviceName') || t('journey.header');
|
56
|
+
err.title = t('errors.submission-rate-limit.title');
|
57
|
+
err.message = t('errors.submission-rate-limit.message');
|
58
|
+
err.preTimeToWait = t('errors.submission-rate-limit.pre-time-to-wait');
|
59
|
+
err.timeToWait = rateLimitsConfig.rateLimits.submissions.windowSizeInMinutes;
|
60
|
+
err.postTimeToWait = t('errors.submission-rate-limit.post-time-to-wait');
|
61
|
+
content.serviceName = t('journey.serviceName') || t('journey.header');
|
62
|
+
content.title = t('errors.submission-rate-limit.title');
|
63
|
+
content.message = t('errors.submission-rate-limit.message');
|
64
|
+
content.preTimeToWait = t('errors.submission-rate-limit.pre-time-to-wait');
|
65
|
+
content.timeToWait = rateLimitsConfig.rateLimits.submissions.windowSizeInMinutes;
|
66
|
+
content.postTimeToWait = t('errors.submission-rate-limit.post-time-to-wait');
|
67
|
+
}
|
68
|
+
|
69
|
+
err.code = err.code || 'UNKNOWN';
|
70
|
+
err.status = err.status || 500;
|
71
|
+
|
72
|
+
if (!content.title) {
|
73
|
+
content.title = t('errors.default.title') || errorTitle(err.code);
|
74
|
+
}
|
75
|
+
if (!content.message) {
|
76
|
+
content.message = t('errors.default.message') || errorMsg(err.code);
|
77
|
+
}
|
78
|
+
return content;
|
79
|
+
};
|
80
|
+
|
81
|
+
const returnBaseUrl = url => {
|
82
|
+
const splitUrl = url.split('/');
|
83
|
+
if (splitUrl.length > 2) {
|
84
|
+
return `/${splitUrl[1]}`;
|
85
|
+
}
|
86
|
+
return '/';
|
87
|
+
};
|
88
|
+
|
89
|
+
module.exports = options => {
|
90
|
+
const opts = options || {};
|
91
|
+
const logger = opts.logger;
|
92
|
+
const debug = opts.debug;
|
93
|
+
|
94
|
+
return (err, req, res, next) => {
|
95
|
+
const translate = opts.translate || req.translate;
|
96
|
+
const content = getContent(err, translate);
|
97
|
+
const locals = {
|
98
|
+
error: err,
|
99
|
+
serviceName: content.serviceName,
|
100
|
+
content: debug === true ? err : content,
|
101
|
+
showStack: debug === true,
|
102
|
+
startLink: returnBaseUrl(req.path),
|
103
|
+
baseUrl: returnBaseUrl(req.path)
|
104
|
+
};
|
105
|
+
|
106
|
+
if (logger && logger.error) {
|
107
|
+
logger.error(err.message || err.error, err);
|
108
|
+
}
|
109
|
+
|
110
|
+
res.status(err.status);
|
111
|
+
res.render(err.template || 'error', locals, (e, html) => {
|
112
|
+
if (e) {
|
113
|
+
res.render('error', locals);
|
114
|
+
} else {
|
115
|
+
res.send(html);
|
116
|
+
}
|
117
|
+
});
|
118
|
+
};
|
119
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
module.exports = {
|
4
|
+
cookies: require('./cookies'),
|
5
|
+
errors: require('./errors'),
|
6
|
+
notFound: require('./not-found'),
|
7
|
+
deepTranslate: require('./deep-translate'),
|
8
|
+
rateLimiter: require('./rate-limiter'),
|
9
|
+
serviceUnavailable: require('./service-unavailable')
|
10
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const getTranslations = translate => {
|
4
|
+
const translations = {
|
5
|
+
title: 'Not found',
|
6
|
+
description: 'There is nothing here'
|
7
|
+
};
|
8
|
+
|
9
|
+
if (translate) {
|
10
|
+
translations.title = translate('errors.404.title');
|
11
|
+
translations.description = translate('errors.404.description');
|
12
|
+
}
|
13
|
+
|
14
|
+
return translations;
|
15
|
+
};
|
16
|
+
|
17
|
+
module.exports = options => {
|
18
|
+
const opts = options || {};
|
19
|
+
const logger = opts.logger;
|
20
|
+
|
21
|
+
return (req, res) => {
|
22
|
+
const translate = opts.translate || req.translate;
|
23
|
+
const translations = getTranslations(translate);
|
24
|
+
|
25
|
+
if (logger && logger.warn) {
|
26
|
+
logger.warn(`Cannot find: ${req.url}`);
|
27
|
+
}
|
28
|
+
|
29
|
+
res.status(404).render('404', {
|
30
|
+
title: translations.title,
|
31
|
+
description: translations.description,
|
32
|
+
// Finds the first word in the path of the
|
33
|
+
// url and removes the leading slash.
|
34
|
+
// Where url is `/foo/bar`, this returns `foo`.
|
35
|
+
startLink: req.url.replace(/^\/([^\/]*).*$/, '$1')
|
36
|
+
});
|
37
|
+
};
|
38
|
+
};
|