@cley_faye/boilerplate 3.7.0 → 3.8.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/README.md +3 -2
- package/lib/express/middlewares/bodylogger.d.ts +5 -1
- package/lib/express/middlewares/bodylogger.js +36 -2
- package/lib/express.d.ts +10 -1
- package/lib/express.js +13 -4
- package/lib/grunt/reactapp.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -426,7 +426,7 @@ import {appStart} from "@cley_faye/boilerplate/lib/express.js";
|
|
|
426
426
|
|
|
427
427
|
appStart({
|
|
428
428
|
app,
|
|
429
|
-
|
|
429
|
+
listenInterface: false,
|
|
430
430
|
port: 3000,
|
|
431
431
|
shutdownFunction: () => {;},
|
|
432
432
|
logger: consoleLogger,
|
|
@@ -435,7 +435,8 @@ appStart({
|
|
|
435
435
|
|
|
436
436
|
The settings are:
|
|
437
437
|
|
|
438
|
-
-
|
|
438
|
+
- listenInterface: listen only to localhost or not. Can also be used to specify the address of an
|
|
439
|
+
interface to bind to.
|
|
439
440
|
- port: port to listen to. Can be 0 to use a random available port
|
|
440
441
|
- shutdownFunction: a function to call after the server stop listening
|
|
441
442
|
- logger: a winston logger to log that the server started listening
|
|
@@ -2,4 +2,8 @@ import { NextFunction, Request, Response } from "express";
|
|
|
2
2
|
export declare type ExtraLoggingDataType = Record<string, unknown> | undefined;
|
|
3
3
|
export declare type ExtraLoggingDataFunc = (req: Request) => Promise<ExtraLoggingDataType> | ExtraLoggingDataType;
|
|
4
4
|
export declare type ExtraLoggingData = ExtraLoggingDataFunc | Record<string, unknown>;
|
|
5
|
-
export
|
|
5
|
+
export interface ExtraLoggingOptions {
|
|
6
|
+
/** Do not expose the "hidden" body props */
|
|
7
|
+
noHiddenBodyProps?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const bodyLogger: (bodyProps?: string[] | undefined, extraLoggingData?: ExtraLoggingData | undefined, options?: ExtraLoggingOptions) => (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -38,12 +38,46 @@ const setLogInfoInReq = (req, body, extraData) => {
|
|
|
38
38
|
castReq._cleyfayeLogging = { extraLoggingData: extraData };
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
const
|
|
41
|
+
const getPropType = (value) => {
|
|
42
|
+
if (typeof value === "string")
|
|
43
|
+
return `string(${value.length})`;
|
|
44
|
+
if (typeof value === "number")
|
|
45
|
+
return "number";
|
|
46
|
+
if (typeof value === "boolean")
|
|
47
|
+
return "boolean";
|
|
48
|
+
if (typeof value === "undefined")
|
|
49
|
+
return "undefined";
|
|
50
|
+
if (Array.isArray(value))
|
|
51
|
+
return `Array(${value.length})`;
|
|
52
|
+
return "object";
|
|
53
|
+
};
|
|
54
|
+
const getHiddenBodyProps = (req, ignoreKeys = []) => {
|
|
55
|
+
if (typeof req.body !== "object")
|
|
56
|
+
return;
|
|
57
|
+
const body = req.body;
|
|
58
|
+
const res = {};
|
|
59
|
+
for (const key of Object.keys(body)) {
|
|
60
|
+
if (ignoreKeys.includes(key))
|
|
61
|
+
continue;
|
|
62
|
+
res[key] = getPropType(body[key]);
|
|
63
|
+
}
|
|
64
|
+
if (Object.keys(res).length === 0)
|
|
65
|
+
return;
|
|
66
|
+
return res;
|
|
67
|
+
};
|
|
68
|
+
const bodyLogger = (bodyProps, extraLoggingData, options = {}) => (req, res, next) => {
|
|
42
69
|
const asyncFunc = async () => {
|
|
70
|
+
const allExtraData = {};
|
|
71
|
+
if (!options.noHiddenBodyProps) {
|
|
72
|
+
const redactedBody = getHiddenBodyProps(req, bodyProps);
|
|
73
|
+
if (redactedBody)
|
|
74
|
+
Object.assign(allExtraData, { redactedBody });
|
|
75
|
+
}
|
|
43
76
|
const extraLogData = typeof extraLoggingData === "function"
|
|
44
77
|
? await extraLoggingData(req)
|
|
45
78
|
: extraLoggingData;
|
|
46
|
-
|
|
79
|
+
Object.assign(allExtraData, extraLogData);
|
|
80
|
+
setLogInfoInReq(req, bodyProps, allExtraData);
|
|
47
81
|
};
|
|
48
82
|
asyncFunc()
|
|
49
83
|
.then(() => {
|
package/lib/express.d.ts
CHANGED
|
@@ -106,7 +106,16 @@ export declare const createPipeline: (settings: PipelineSettings, debugLog?: Log
|
|
|
106
106
|
export declare const setViewEngine: (app: express.Express, viewEngine: string, viewsDirectory: string, extraLocals?: Record<string, string | number> | undefined) => void;
|
|
107
107
|
export interface StartDefinition {
|
|
108
108
|
app: express.Application;
|
|
109
|
+
/** @deprecated use listenInterface instead */
|
|
109
110
|
allowNonLocal?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Which interface to listen on.
|
|
113
|
+
*
|
|
114
|
+
* Defaults to `false` which means listen only on localhost.
|
|
115
|
+
* Set to `true` to listen on all interfaces
|
|
116
|
+
* Set to an IP to bind on a specific interface.
|
|
117
|
+
*/
|
|
118
|
+
listenInterface?: boolean | string;
|
|
110
119
|
port?: number;
|
|
111
120
|
shutdownFunction?: () => void;
|
|
112
121
|
logger?: winston.Logger;
|
|
@@ -135,4 +144,4 @@ export interface StartResult {
|
|
|
135
144
|
*
|
|
136
145
|
* @property server
|
|
137
146
|
*/
|
|
138
|
-
export declare const appStart: ({ app, allowNonLocal, port, shutdownFunction, logger, }: StartDefinition) => Promise<StartResult>;
|
|
147
|
+
export declare const appStart: ({ app, allowNonLocal, listenInterface, port, shutdownFunction, logger, }: StartDefinition) => Promise<StartResult>;
|
package/lib/express.js
CHANGED
|
@@ -169,7 +169,7 @@ exports.setViewEngine = setViewEngine;
|
|
|
169
169
|
*
|
|
170
170
|
* @property server
|
|
171
171
|
*/
|
|
172
|
-
const appStart = ({ app, allowNonLocal, port, shutdownFunction, logger, }) => new Promise(resolve => {
|
|
172
|
+
const appStart = ({ app, allowNonLocal, listenInterface, port, shutdownFunction, logger, }) => new Promise(resolve => {
|
|
173
173
|
let server = null;
|
|
174
174
|
const readyCallback = () => {
|
|
175
175
|
if (server === null) {
|
|
@@ -186,9 +186,18 @@ const appStart = ({ app, allowNonLocal, port, shutdownFunction, logger, }) => ne
|
|
|
186
186
|
server,
|
|
187
187
|
});
|
|
188
188
|
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
if (allowNonLocal !== undefined && listenInterface !== undefined) {
|
|
190
|
+
throw new Error("You can't specify both allowNonLocal and listenInterface at the same time");
|
|
191
|
+
}
|
|
192
|
+
if (allowNonLocal || listenInterface === true) {
|
|
193
|
+
server = app.listen(port ?? 0, readyCallback);
|
|
194
|
+
}
|
|
195
|
+
else if (typeof listenInterface === "string") {
|
|
196
|
+
server = app.listen(port ?? 0, listenInterface, readyCallback);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
server = app.listen(port ?? 0, "localhost", readyCallback);
|
|
200
|
+
}
|
|
192
201
|
if (shutdownFunction) {
|
|
193
202
|
server.on("close", shutdownFunction);
|
|
194
203
|
}
|
package/lib/grunt/reactapp.js
CHANGED
|
@@ -49,7 +49,7 @@ var HandlerType;
|
|
|
49
49
|
HandlerType["COPY"] = "copy";
|
|
50
50
|
})(HandlerType = exports.HandlerType || (exports.HandlerType = {}));
|
|
51
51
|
const gatherTasks = (handlers, gruntConfig, targetName, options) => Object.keys(handlers)
|
|
52
|
-
.reduce((acc, cur) => acc.concat((options?.[cur] &&
|
|
52
|
+
.reduce((acc, cur) => acc.concat((options?.[cur] && options[cur]?.disabled)
|
|
53
53
|
? []
|
|
54
54
|
: handlers[cur](gruntConfig, targetName, (options?.[cur]) ?? {})), []);
|
|
55
55
|
const mergeResults = (tasksResults) => tasksResults.reduce((acc, cur) => {
|
|
@@ -184,7 +184,8 @@ const reactApp = (gruntConfig, targetName = "reactApp", options) => {
|
|
|
184
184
|
};
|
|
185
185
|
const tasksResults = gatherTasks(handlers, gruntConfig, targetName, options);
|
|
186
186
|
const mergedResults = mergeResults(tasksResults);
|
|
187
|
-
|
|
187
|
+
if (!options?.copy?.disabled)
|
|
188
|
+
createCopyTask(gruntConfig, targetName, mergedResults, options);
|
|
188
189
|
// Add grunt-contrib-watch task
|
|
189
190
|
createWatchTasks(gruntConfig, mergedResults, options?.watch);
|
|
190
191
|
return mergedResults.requiredTasks;
|