@apolitical/server 3.0.0-beta.1 → 3.0.0
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/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { NODE_ENV, LOG_LEVEL } = process.env;
|
|
4
4
|
|
|
5
5
|
const NAME = 'apolitical-server';
|
|
6
|
-
const UUID = '
|
|
6
|
+
const UUID = '00000000-0000-0000-0000-000000000000';
|
|
7
7
|
const VERSION = '2.6.0';
|
|
8
8
|
const ADMIN_ROLE = 'administrator';
|
|
9
9
|
|
|
@@ -54,9 +54,9 @@ module.exports = {
|
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
56
|
MORGAN_OPTIONS: {
|
|
57
|
-
|
|
57
|
+
LOGGED_OUT_ID: 'logged-out',
|
|
58
58
|
TOKENS: {
|
|
59
|
-
|
|
59
|
+
USER_ID: 'user-id',
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
CACHE_OPTIONS: {
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = ({ morgan, config, logger }) => {
|
|
4
4
|
const {
|
|
5
|
-
|
|
6
|
-
TOKENS: {
|
|
5
|
+
LOGGED_OUT_ID,
|
|
6
|
+
TOKENS: { USER_ID },
|
|
7
7
|
} = config.SERVER.MORGAN_OPTIONS;
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
return req.user && req.user.
|
|
9
|
+
function getUserId(req) {
|
|
10
|
+
return req.user && req.user.id ? req.user.id : LOGGED_OUT_ID;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function buildCustomFormat(tokens, req, res) {
|
|
@@ -15,7 +15,7 @@ module.exports = ({ morgan, config, logger }) => {
|
|
|
15
15
|
tokens.method(req, res),
|
|
16
16
|
tokens.url(req, res),
|
|
17
17
|
tokens.status(req, res),
|
|
18
|
-
tokens[
|
|
18
|
+
tokens[USER_ID](req),
|
|
19
19
|
tokens['response-time'](req, res),
|
|
20
20
|
'ms',
|
|
21
21
|
].join(' ');
|
|
@@ -23,10 +23,10 @@ module.exports = ({ morgan, config, logger }) => {
|
|
|
23
23
|
|
|
24
24
|
function buildMiddleware(labels) {
|
|
25
25
|
// Setup Morgan with custom format and Apolitical Logger stream
|
|
26
|
-
morgan.token(
|
|
26
|
+
morgan.token(USER_ID, getUserId);
|
|
27
27
|
const morganMiddleware = morgan(buildCustomFormat, logger.where(__filename, 'morganMiddleware', labels));
|
|
28
28
|
return morganMiddleware;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return {
|
|
31
|
+
return { getUserId, buildMiddleware };
|
|
32
32
|
};
|
|
@@ -7,7 +7,7 @@ module.exports =
|
|
|
7
7
|
JWT: { AUTH0 },
|
|
8
8
|
},
|
|
9
9
|
logger,
|
|
10
|
-
loggerHelper: {
|
|
10
|
+
loggerHelper: { getUserId },
|
|
11
11
|
serverError: { GeneralError },
|
|
12
12
|
}) =>
|
|
13
13
|
({ labels, redirectURL, fallbackController }) => {
|
|
@@ -35,12 +35,12 @@ module.exports =
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
// Log the error with all the relevent info
|
|
38
|
-
const
|
|
38
|
+
const userId = getUserId(req);
|
|
39
39
|
if (req.log) {
|
|
40
|
-
req.log.warn(message, { errors,
|
|
40
|
+
req.log.warn(message, { errors, userId });
|
|
41
41
|
} else {
|
|
42
42
|
const errorLogger = logger.where(__filename, 'handler', labels);
|
|
43
|
-
errorLogger.warn(message, { errors,
|
|
43
|
+
errorLogger.warn(message, { errors, userId });
|
|
44
44
|
}
|
|
45
45
|
// Use the redirect URL to redirect the request
|
|
46
46
|
if (redirectURL) {
|