@apolitical/server 2.0.1 → 2.1.1
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
CHANGED
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.1.1] - 2022-01-31
|
|
9
|
+
### Fixed
|
|
10
|
+
- Authorisation logic
|
|
11
|
+
|
|
12
|
+
## [2.1.0] - 2022-01-21
|
|
13
|
+
### Added
|
|
14
|
+
- Prerender middleware
|
|
15
|
+
### Fixed
|
|
16
|
+
- Node.js version
|
|
17
|
+
|
|
8
18
|
## [2.0.1] - 2022-01-21
|
|
9
19
|
### Added
|
|
10
20
|
- Correlation when logging from error middleware
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apolitical/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Node.js module to encapsulate Apolitical's express server setup",
|
|
5
5
|
"author": "Apolitical Group Limited <engineering@apolitical.co>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"Node Modules"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@apolitical/logger": "2.0.
|
|
27
|
+
"@apolitical/logger": "2.0.1",
|
|
28
28
|
"@cloudnative/health-connect": "2.1.0",
|
|
29
|
-
"awilix": "6.
|
|
29
|
+
"awilix": "6.1.0",
|
|
30
30
|
"body-parser": "1.19.1",
|
|
31
31
|
"compression": "1.7.4",
|
|
32
32
|
"cookie-parser": "1.4.6",
|
|
33
33
|
"cors": "2.8.5",
|
|
34
|
-
"dotenv": "
|
|
34
|
+
"dotenv": "15.0.0",
|
|
35
35
|
"express": "4.17.2",
|
|
36
36
|
"express-jwt": "6.1.0",
|
|
37
37
|
"http-status-codes": "2.2.0",
|
|
@@ -42,21 +42,22 @@
|
|
|
42
42
|
"morgan": "1.10.0",
|
|
43
43
|
"passport": "0.5.2",
|
|
44
44
|
"passport-jwt": "4.0.0",
|
|
45
|
+
"prerender-node": "3.4.1",
|
|
45
46
|
"swagger-ui-express": "4.3.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@apolitical/eslint-config": "1.0.
|
|
49
|
-
"@apolitical/testing": "1.0.
|
|
49
|
+
"@apolitical/eslint-config": "1.0.2",
|
|
50
|
+
"@apolitical/testing": "1.0.2",
|
|
50
51
|
"audit-ci": "5.1.2",
|
|
51
52
|
"husky": "7.0.4",
|
|
52
53
|
"jest": "27.4.7",
|
|
53
54
|
"jest-junit": "13.0.0",
|
|
54
|
-
"lint-staged": "12.
|
|
55
|
+
"lint-staged": "12.3.2",
|
|
55
56
|
"mock-jwks": "1.0.1",
|
|
56
57
|
"nock": "13.2.2"
|
|
57
58
|
},
|
|
58
59
|
"engines": {
|
|
59
|
-
"node": ">=16.13.
|
|
60
|
+
"node": ">=16.13.0"
|
|
60
61
|
},
|
|
61
62
|
"eslintConfig": {
|
|
62
63
|
"extends": "@apolitical/eslint-config/base.config"
|
package/src/container.js
CHANGED
|
@@ -17,6 +17,7 @@ const jwtDecode = require('jwt-decode');
|
|
|
17
17
|
const morgan = require('morgan');
|
|
18
18
|
const passport = require('passport');
|
|
19
19
|
const passportJwt = require('passport-jwt');
|
|
20
|
+
const prerender = require('prerender-node');
|
|
20
21
|
const swaggerUi = require('swagger-ui-express');
|
|
21
22
|
// Internal Modules
|
|
22
23
|
const apoliticalLogger = require('@apolitical/logger');
|
|
@@ -65,6 +66,7 @@ container.register({
|
|
|
65
66
|
morgan: asValue(morgan),
|
|
66
67
|
passport: asValue(passport),
|
|
67
68
|
passportJwt: asValue(passportJwt),
|
|
69
|
+
prerender: asValue(prerender),
|
|
68
70
|
swaggerUi: asValue(swaggerUi),
|
|
69
71
|
// Internal Modules
|
|
70
72
|
apoliticalLogger: asValue(apoliticalLogger),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports = ({ bodyParser: { json, urlencoded }, compression, cors, cookieParser, config, logger }) => {
|
|
3
|
+
module.exports = ({ bodyParser: { json, urlencoded }, compression, cors, cookieParser, prerender, config, logger }) => {
|
|
4
4
|
const { BODY_PARSER_OPTIONS, CORS_OPTIONS } = config.SERVER;
|
|
5
5
|
|
|
6
|
-
return function load(app, { corsOptions }) {
|
|
6
|
+
return function load(app, { corsOptions, prerenderToken }) {
|
|
7
7
|
const childLogger = logger.where(__filename, 'load');
|
|
8
8
|
childLogger.debug('Started');
|
|
9
9
|
// Load useful middlewares
|
|
@@ -12,6 +12,9 @@ module.exports = ({ bodyParser: { json, urlencoded }, compression, cors, cookieP
|
|
|
12
12
|
app.use(urlencoded(BODY_PARSER_OPTIONS));
|
|
13
13
|
app.use(cors(Object.assign({}, CORS_OPTIONS, corsOptions)));
|
|
14
14
|
app.use(compression());
|
|
15
|
+
if (prerenderToken) {
|
|
16
|
+
app.use(prerender.set('prerenderToken', prerenderToken));
|
|
17
|
+
}
|
|
15
18
|
childLogger.debug('Finished');
|
|
16
19
|
};
|
|
17
20
|
};
|
|
@@ -8,21 +8,21 @@ module.exports = ({ logger, serverError: { Forbidden }, config }) => {
|
|
|
8
8
|
return function handler(req, res, next) {
|
|
9
9
|
const childLogger = logger.where(__filename, 'handler');
|
|
10
10
|
childLogger.debug('Started');
|
|
11
|
-
let isNotMyselfSlug = false;
|
|
12
11
|
let isNotAdmin = false;
|
|
13
|
-
|
|
14
|
-
if (myselfSource) {
|
|
15
|
-
isNotMyselfSlug = req.params[myselfSource] !== MYSELF_SLUG;
|
|
16
|
-
}
|
|
12
|
+
let isNotMyselfSlug = false;
|
|
17
13
|
// Check user role (from JWT)
|
|
18
14
|
if (!allowNonAdmin) {
|
|
19
15
|
isNotAdmin = req.user && req.user.role !== ADMIN_ROLE;
|
|
20
16
|
}
|
|
17
|
+
// Check myself param
|
|
18
|
+
if (myselfSource) {
|
|
19
|
+
isNotMyselfSlug = req.params[myselfSource] !== MYSELF_SLUG;
|
|
20
|
+
}
|
|
21
21
|
// Check permissions and prevent unauthorised requests
|
|
22
22
|
let unauthorised = false;
|
|
23
|
-
if (
|
|
23
|
+
if (!allowNonAdmin && isNotAdmin && isNotMyselfSlug) {
|
|
24
24
|
unauthorised = true;
|
|
25
|
-
} else if (isNotAdmin && !
|
|
25
|
+
} else if (!allowNonAdmin && isNotAdmin && !myselfSource) {
|
|
26
26
|
unauthorised = true;
|
|
27
27
|
}
|
|
28
28
|
if (unauthorised) {
|