Skip to content

Commit

Permalink
fix: Adopt common code March 2024 (#33)
Browse files Browse the repository at this point in the history
* fix: Adopt common code March 2024

* fix: Regenerate yarn.lock
  • Loading branch information
georgegillams authored Mar 7, 2024
1 parent bf41862 commit 7823033
Show file tree
Hide file tree
Showing 43 changed files with 6,870 additions and 6,117 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.10.0
v20
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:16.10.0
ARG NODE_VERSION=20

FROM node:${NODE_VERSION}

WORKDIR /usr/src/tmp

Expand Down
4 changes: 3 additions & 1 deletion DockerfileProd
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:16.10.0
ARG NODE_VERSION=20

FROM node:${NODE_VERSION}

ARG REDIS_URL
ENV REDIS_URL=$REDIS_URL
Expand Down
102 changes: 49 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,91 +52,87 @@
]
},
"dependencies": {
"@george-gillams/components": "^28.5.12",
"@george-gillams/webapp": "1.0.1",
"@next/bundle-analyzer": "^13.0.3",
"async-lock": "^1.4.0",
"bcrypt": "^5.1.0",
"body-parser": "^1.20.1",
"chalk": "^4.1.0",
"@george-gillams/components": "^28.15.0",
"@george-gillams/webapp": "1.0.6",
"@next/bundle-analyzer": "^14.1.0",
"async-lock": "^1.4.1",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"chalk": "^4.1.2",
"confetti-js": "0.0.18",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"date-fns": "^2.29.3",
"date-fns-tz": "^1.3.7",
"detect-browser": "^5.3.0",
"date-fns-tz": "^2.0.0",
"express": "^4.18.2",
"express-fileupload": "^1.4.0",
"express-slow-down": "^1.5.0",
"flickr-sdk": "^6.0.0",
"helmet": "^6.0.0",
"express-fileupload": "^1.4.3",
"express-slow-down": "^2.0.1",
"helmet": "^7.1.0",
"hoist-non-react-statics": "3.3.2",
"immer": "^9.0.16",
"immutable": "^4.1.0",
"immutable": "^4.3.5",
"invariant": "2.2.4",
"ip": "^1.1.8",
"ip": "^2.0.1",
"ip-parse": "^1.0.5",
"konami": "^1.6.3",
"lodash": "^4.17.21",
"next": "^13.0.3",
"next-transpile-modules": "^10.0.0",
"nodemailer": "^6.8.0",
"next": "^14.1.0",
"next-transpile-modules": "^10.0.1",
"nodemailer": "^6.9.10",
"normalize.css": "^8.0.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-cookies": "^0.1.1",
"react-dom": "^18.2.0",
"react-loadable": "^5.5.0",
"react-modal": "^3.16.1",
"react-photo-gallery": "^8.0.0",
"react-redux": "8.0.5",
"react-redux": "8.1.3",
"redis": "^3.1.2",
"redux": "4.2.0",
"redux-saga": "1.2.1",
"redux": "4.2.1",
"redux-saga": "1.3.0",
"redux-saga-routines": "^3.2.3",
"reselect": "4.1.7",
"reselect": "4.1.8",
"safe-compare": "^1.1.4",
"signale": "^1.4.0",
"stripe": "^11.0.0",
"styled-components": "^5.3.6",
"styled-normalize": "^8.0.7",
"wget-improved": "^3.3.1",
"whatwg-fetch": "^3.6.2"
"styled-normalize": "^8.1.1",
"wget-improved": "^3.4.0",
"whatwg-fetch": "^3.6.20"
},
"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/eslint-parser": "^7.19.1",
"@babel/node": "^7.20.2",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/cli": "^7.23.9",
"@babel/eslint-parser": "^7.23.10",
"@babel/node": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/preset-react": "^7.23.3",
"@r-next-b/cli": "^0.1.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"babel-jest": "^29.3.1",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"babel-jest": "^29.7.0",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-module-resolver": "^4.1.0",
"backstopjs": "^6.1.4",
"babel-plugin-module-resolver": "^5.0.0",
"babel-plugin-styled-components": "^2.1.4",
"backstopjs": "^6.3.10",
"coveralls": "^3.1.1",
"css-loader": "^6.7.2",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-prettier": "^4.2.1",
"css-loader": "^6.10.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-redux-saga": "^1.3.2",
"husky": "^8.0.2",
"jest-cli": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-styled-components": "^7.1.1",
"lint-staged": "^13.0.3",
"nodemon": "^2.0.20",
"prettier": "^2.7.1",
"husky": "^9.0.11",
"jest-cli": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-styled-components": "^7.2.0",
"lint-staged": "^15.2.2",
"nodemon": "^3.0.3",
"prettier": "^3.2.5",
"prompt": "^1.3.0",
"react-test-renderer": "^18.2.0",
"redis-mock": "^0.56.3"
Expand Down
73 changes: 37 additions & 36 deletions server/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CategorisedError, InternalServerError, NotImplementedError } from 'serv
import { mapPathToAction } from 'server-utils/common/mapPathToAction.js';
import logger from 'server-utils/common/logger';

const appFunc = (req, res) => {
const appFunc = async (req, res) => {
const splitUrlPath = req.url.split('?')[0].split('/').slice(1);

const pathMatches = mapPathToAction(apiStructure, splitUrlPath);
Expand Down Expand Up @@ -35,41 +35,42 @@ const appFunc = (req, res) => {

try {
if (action) {
action(req, params)
.then(result => {
if (result instanceof Function) {
result(res);
} else {
res.json(result);
}
return true;
})
.catch(err => {
if (err && err.redirect) {
res.redirect(err.redirect);
} else if (err instanceof CategorisedError) {
res.status(err.httpStatus);
res.json({ error: err.category, errorMessage: err.message });
} else if (err instanceof Error) {
// An error that we haven't created. Maybe created by redis or something
logger.error(`Uncategorised error`, err);
const internalServerError = new InternalServerError(err.message);
res.status(internalServerError.httpStatus);
res.json({
error: internalServerError.category,
errorMessage: internalServerError.message,
});
} else {
// The error is an invalid object format, instead of being an instance of Error
logger.error(`LEGACY ERROR - a promise rejected an object instead of an actual Error`, err);
const internalServerError = new InternalServerError(err.message);
res.status(internalServerError.httpStatus);
res.json({
error: internalServerError.category,
errorMessage: internalServerError.message,
});
}
});
try {
const result = await action(req, params);
if (result instanceof Function) {
result(res);
} else {
res.json(result);
}
return true;
} catch (err) {
if (err && err.redirect) {
res.redirect(err.redirect);
} else if (err instanceof CategorisedError) {
res.status(err.httpStatus);
res.json({ error: err.category, errorMessage: err.message });
} else if (err instanceof Error) {
// An error that we haven't created. Maybe created by redis or something
logger.error(`Uncategorised error`, err);
// Do not expose errors that we did not create to the client
const internalServerError = new InternalServerError('An unknown error occurred');
res.status(internalServerError.httpStatus);
res.json({
error: internalServerError.category,
errorMessage: internalServerError.message,
});
} else {
// The error is an invalid object format, instead of being an instance of Error
logger.error(`LEGACY ERROR - a promise rejected an object instead of an actual Error`, err);
// Do not expose errors that we did not create to the client
const internalServerError = new InternalServerError('An unknown error occurred');
res.status(internalServerError.httpStatus);
res.json({
error: internalServerError.category,
errorMessage: internalServerError.message,
});
}
}
} else {
const err = new NotImplementedError('This method has not been implemented');
res.status(err.httpStatus);
Expand Down
3 changes: 1 addition & 2 deletions server/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const applySecurityPractises = server => {
contentSecurityPolicy: {
directives: cspDirectives,
},
crossOriginEmbedderPolicy: false,
})
);

Expand All @@ -58,7 +57,7 @@ const applySecurityPractises = server => {
slowDown({
windowMs: 15 * 60 * 1000, // 15 minutes
delayAfter: 5, // allow 5 requests per window without limiting...
delayMs: 500, // add 1s delay per request above 5...
delayMs: used => (used - this.delayAfter) * 500, // add .5s delay per request above 5...
maxDelayMs: 10000, // with a maximum delay of 10 seconds
// request # 1 no delay
// ...
Expand Down
2 changes: 2 additions & 0 deletions server/utils/common/logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

const chalk = require('chalk');
import { ip } from 'ip';

Expand Down
Loading

0 comments on commit 7823033

Please sign in to comment.