@cley_faye/boilerplate 3.21.3 → 4.0.2
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 +7 -219
- package/bin/serve_spa.js +0 -1
- package/lib/bin/serve_spa.js +67 -39
- package/lib/express/middlewares/singlepageapp.d.ts +2 -2
- package/lib/express/middlewares/singlepageapp.js +20 -13
- package/lib/grunt/args.d.ts +14 -42
- package/lib/grunt/args.js +27 -41
- package/lib/grunt/reactapp/copy.d.ts +8 -34
- package/lib/grunt/reactapp/copy.js +47 -49
- package/lib/grunt/reactapp/image.d.ts +8 -23
- package/lib/grunt/reactapp/image.js +45 -42
- package/lib/grunt/reactapp/pug.d.ts +8 -30
- package/lib/grunt/reactapp/pug.js +49 -50
- package/lib/grunt/reactapp/sass.d.ts +8 -29
- package/lib/grunt/reactapp/sass.js +48 -43
- package/lib/grunt/reactapp/util.d.ts +5 -9
- package/lib/grunt/reactapp/util.js +12 -15
- package/lib/grunt/reactapp/webpack.d.ts +9 -80
- package/lib/grunt/reactapp/webpack.js +71 -125
- package/lib/grunt/reactapp.d.ts +22 -64
- package/lib/grunt/reactapp.js +70 -93
- package/lib/grunt/util.d.ts +4 -7
- package/lib/grunt/util.js +5 -8
- package/lib/grunt.d.ts +2 -3
- package/lib/grunt.js +5 -5
- package/lib/util.js +5 -4
- package/package.json +23 -30
- package/grunt.js +0 -3
- package/lib/express/autoclose.d.ts +0 -17
- package/lib/express/autoclose.js +0 -76
- package/lib/express/logger.d.ts +0 -25
- package/lib/express/logger.js +0 -132
- package/lib/express/middlewares/bodylogger.d.ts +0 -9
- package/lib/express/middlewares/bodylogger.js +0 -90
- package/lib/express/pipelinebuilder.d.ts +0 -115
- package/lib/express/pipelinebuilder.js +0 -288
- package/lib/express/unprocessableentityerror.d.ts +0 -8
- package/lib/express/unprocessableentityerror.js +0 -57
- package/lib/express.d.ts +0 -156
- package/lib/express.js +0 -218
- package/lib/repl.d.ts +0 -27
- package/lib/repl.js +0 -68
- package/lib/winston.d.ts +0 -38
- package/lib/winston.js +0 -224
package/lib/express/autoclose.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* @preserve
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 Gabriel Paul "Cley Faye" Risterucci
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
"use strict";
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.setSignalHandler = exports.closeServer = exports.unsetRef = exports.setRef = void 0;
|
|
30
|
-
const serverRefs = [];
|
|
31
|
-
/** Store a server instance for closing it later.
|
|
32
|
-
*
|
|
33
|
-
* @param {Object} ref
|
|
34
|
-
* The server instance
|
|
35
|
-
*/
|
|
36
|
-
const setRef = (ref) => {
|
|
37
|
-
if (serverRefs.includes(ref)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
serverRefs.push(ref);
|
|
41
|
-
};
|
|
42
|
-
exports.setRef = setRef;
|
|
43
|
-
/** Remove a server instance from the closing list.
|
|
44
|
-
*
|
|
45
|
-
* @param {Object} ref
|
|
46
|
-
* The server instance
|
|
47
|
-
*/
|
|
48
|
-
const unsetRef = (ref) => {
|
|
49
|
-
if (!serverRefs.includes(ref)) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
serverRefs.splice(serverRefs.indexOf(ref), 1);
|
|
53
|
-
};
|
|
54
|
-
exports.unsetRef = unsetRef;
|
|
55
|
-
/** Close the stored server reference */
|
|
56
|
-
const closeServer = () => {
|
|
57
|
-
serverRefs.forEach(ref => ref.close());
|
|
58
|
-
serverRefs.length = 0;
|
|
59
|
-
};
|
|
60
|
-
exports.closeServer = closeServer;
|
|
61
|
-
/** Stop the server on SIGINT */
|
|
62
|
-
const setSignalHandler = () => {
|
|
63
|
-
if (process.platform === "win32") {
|
|
64
|
-
process.on("message", msg => {
|
|
65
|
-
if (msg === "shutdown") {
|
|
66
|
-
(0, exports.closeServer)();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
process.on("SIGINT", () => {
|
|
72
|
-
(0, exports.closeServer)();
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
exports.setSignalHandler = setSignalHandler;
|
package/lib/express/logger.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import expressWinston, { BaseLoggerOptions } from "express-winston";
|
|
2
|
-
import { Request, Router } from "express";
|
|
3
|
-
import { LogOptions, UserFromReqFunc } from "./pipelinebuilder.js";
|
|
4
|
-
export type LoggerOptions = expressWinston.BaseLoggerOptions | boolean;
|
|
5
|
-
interface ErrorLoggerConfiguration {
|
|
6
|
-
/** @deprecated Use collapseStacktrace */
|
|
7
|
-
collapseNodeModules?: boolean;
|
|
8
|
-
collapseStacktrace?: boolean;
|
|
9
|
-
extraFilter?: Array<RegExp> | RegExp;
|
|
10
|
-
}
|
|
11
|
-
export type ErrorLoggerOptions = ErrorLoggerConfiguration | boolean;
|
|
12
|
-
export interface LoggingData {
|
|
13
|
-
extraLoggingData?: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
export interface RequestWithLoggingData extends Request {
|
|
16
|
-
_cleyfayeLogging?: LoggingData;
|
|
17
|
-
_routeWhitelists?: {
|
|
18
|
-
body?: Array<string>;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/** Return the default value for route logger is it is set as `true` */
|
|
22
|
-
export declare const defaultRouteLoggerConfig: (authFromReq?: UserFromReqFunc) => BaseLoggerOptions;
|
|
23
|
-
export declare const registerRouteLogger: (app: Router, logOptions?: LogOptions) => void;
|
|
24
|
-
export declare const registerErrorLogger: (app: Router, logOptions?: LogOptions) => void;
|
|
25
|
-
export {};
|
package/lib/express/logger.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* @preserve
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 Gabriel Paul "Cley Faye" Risterucci
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
"use strict";
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.registerErrorLogger = exports.registerRouteLogger = exports.defaultRouteLoggerConfig = void 0;
|
|
33
|
-
const winston_1 = __importDefault(require("winston"));
|
|
34
|
-
const express_winston_1 = __importDefault(require("express-winston"));
|
|
35
|
-
const winston_js_1 = require("../winston.js");
|
|
36
|
-
const customRouteFormat = (outputTimestamp) => winston_1.default.format.printf((info) => {
|
|
37
|
-
const meta = info.meta;
|
|
38
|
-
// Clean the meta object from stuff displayed in the regular message
|
|
39
|
-
if (meta.res?.statusCode) {
|
|
40
|
-
delete meta.res.statusCode;
|
|
41
|
-
}
|
|
42
|
-
if (meta.res) {
|
|
43
|
-
if (Object.keys(meta.res).length === 0) {
|
|
44
|
-
delete meta.res;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if ("responseTime" in meta) {
|
|
48
|
-
delete meta.responseTime;
|
|
49
|
-
}
|
|
50
|
-
if (meta.req) {
|
|
51
|
-
if (Object.keys(meta.req).length === 0) {
|
|
52
|
-
delete meta.req;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const metaString = JSON.stringify(info.meta);
|
|
56
|
-
const finalMessage = `${info.message.toString()} ${metaString === "{}" ? "" : metaString}`;
|
|
57
|
-
return (0, winston_js_1.prefixOutput)(info.level, finalMessage, outputTimestamp);
|
|
58
|
-
});
|
|
59
|
-
/** Return the default value for route logger is it is set as `true` */
|
|
60
|
-
const defaultRouteLoggerConfig = (authFromReq) => ({
|
|
61
|
-
meta: true,
|
|
62
|
-
requestWhitelist: ["body"],
|
|
63
|
-
responseWhitelist: [],
|
|
64
|
-
dynamicMeta: (req) => {
|
|
65
|
-
const castReq = req;
|
|
66
|
-
const data = { ...castReq._cleyfayeLogging?.extraLoggingData };
|
|
67
|
-
if (authFromReq) {
|
|
68
|
-
const value = authFromReq(req);
|
|
69
|
-
if (!value) {
|
|
70
|
-
data.auth = null;
|
|
71
|
-
}
|
|
72
|
-
else if (typeof value === "string") {
|
|
73
|
-
data.auth = value;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
Object.assign(data, value);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return data;
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
exports.defaultRouteLoggerConfig = defaultRouteLoggerConfig;
|
|
83
|
-
const registerRouteLogger = (app, logOptions) => {
|
|
84
|
-
const { route, timestamp, userFromReq, authFromReq, ignoredRoutes } = logOptions ?? {};
|
|
85
|
-
let extraConfig;
|
|
86
|
-
if (typeof route === "boolean") {
|
|
87
|
-
extraConfig = (0, exports.defaultRouteLoggerConfig)(authFromReq ?? userFromReq);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
extraConfig = { ...route };
|
|
91
|
-
const rec = extraConfig;
|
|
92
|
-
if (rec.winstonInstance) {
|
|
93
|
-
delete rec.winstonInstance;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const baseConfig = {
|
|
97
|
-
meta: true,
|
|
98
|
-
requestWhitelist: ["body"],
|
|
99
|
-
bodyWhitelist: [],
|
|
100
|
-
expressFormat: false,
|
|
101
|
-
format: customRouteFormat(timestamp),
|
|
102
|
-
msg: "{{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms",
|
|
103
|
-
ignoredRoutes,
|
|
104
|
-
};
|
|
105
|
-
app.use(express_winston_1.default.logger({
|
|
106
|
-
transports: winston_js_1.transports,
|
|
107
|
-
...baseConfig,
|
|
108
|
-
...extraConfig,
|
|
109
|
-
}));
|
|
110
|
-
};
|
|
111
|
-
exports.registerRouteLogger = registerRouteLogger;
|
|
112
|
-
const getExtraFilter = (userExtraFilter) => {
|
|
113
|
-
const expressRegEx = /node_modules\/express/u;
|
|
114
|
-
if (!userExtraFilter)
|
|
115
|
-
return expressRegEx;
|
|
116
|
-
if (Array.isArray(userExtraFilter))
|
|
117
|
-
return [expressRegEx, ...userExtraFilter];
|
|
118
|
-
return [expressRegEx, userExtraFilter];
|
|
119
|
-
};
|
|
120
|
-
const registerErrorLogger = (app, logOptions) => {
|
|
121
|
-
const { error, logger, timestamp } = logOptions ?? {};
|
|
122
|
-
const config = typeof error === "boolean"
|
|
123
|
-
? {}
|
|
124
|
-
: error ?? {};
|
|
125
|
-
const activeTransports = logger ? logger.transports : winston_js_1.transports;
|
|
126
|
-
app.use(express_winston_1.default.errorLogger({
|
|
127
|
-
transports: activeTransports,
|
|
128
|
-
format: (0, winston_js_1.customFormat)(timestamp, config.collapseStacktrace ?? config.collapseNodeModules, getExtraFilter(config.extraFilter)),
|
|
129
|
-
meta: false,
|
|
130
|
-
}));
|
|
131
|
-
};
|
|
132
|
-
exports.registerErrorLogger = registerErrorLogger;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
export type ExtraLoggingDataType = Record<string, unknown> | undefined;
|
|
3
|
-
export type ExtraLoggingDataFunc = (req: Request) => Promise<ExtraLoggingDataType> | ExtraLoggingDataType;
|
|
4
|
-
export type ExtraLoggingData = ExtraLoggingDataFunc | Record<string, unknown>;
|
|
5
|
-
export interface ExtraLoggingOptions {
|
|
6
|
-
/** Do not expose the "hidden" body props */
|
|
7
|
-
noHiddenBodyProps?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare const bodyLogger: (bodyProps?: Array<string>, extraLoggingData?: ExtraLoggingData, options?: ExtraLoggingOptions) => (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* @preserve
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 Gabriel Paul "Cley Faye" Risterucci
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
"use strict";
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bodyLogger = void 0;
|
|
30
|
-
const setLogInfoInReq = (req, body, extraData) => {
|
|
31
|
-
const castReq = req;
|
|
32
|
-
if (body) {
|
|
33
|
-
if (!castReq._routeWhitelists)
|
|
34
|
-
castReq._routeWhitelists = {};
|
|
35
|
-
castReq._routeWhitelists.body = body;
|
|
36
|
-
}
|
|
37
|
-
if (extraData) {
|
|
38
|
-
castReq._cleyfayeLogging = { extraLoggingData: extraData };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
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) => {
|
|
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
|
-
}
|
|
76
|
-
const extraLogData = typeof extraLoggingData === "function"
|
|
77
|
-
? await extraLoggingData(req)
|
|
78
|
-
: extraLoggingData;
|
|
79
|
-
Object.assign(allExtraData, extraLogData);
|
|
80
|
-
setLogInfoInReq(req, bodyProps, allExtraData);
|
|
81
|
-
};
|
|
82
|
-
asyncFunc()
|
|
83
|
-
.then(() => {
|
|
84
|
-
next();
|
|
85
|
-
})
|
|
86
|
-
.catch((error) => {
|
|
87
|
-
next(error);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
exports.bodyLogger = bodyLogger;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import express, { Request } from "express";
|
|
2
|
-
import { OptionsJson, OptionsUrlencoded, OptionsText, Options as OptionsRaw } from "body-parser";
|
|
3
|
-
import winston from "winston";
|
|
4
|
-
import { LoggerOptions, ErrorLoggerOptions } from "./logger.js";
|
|
5
|
-
export type LogFunction = (...args: Array<string | number | Record<string, unknown>>) => void;
|
|
6
|
-
export interface MiddlewareOptions {
|
|
7
|
-
urlencoded?: boolean | OptionsUrlencoded;
|
|
8
|
-
text?: boolean | OptionsText;
|
|
9
|
-
raw?: boolean | OptionsRaw;
|
|
10
|
-
json?: boolean | OptionsJson;
|
|
11
|
-
}
|
|
12
|
-
export type ComplexRouteHandler = express.RequestHandler | express.Router | Array<express.RequestHandler>;
|
|
13
|
-
export interface ComplexRouteDefinition {
|
|
14
|
-
route: string;
|
|
15
|
-
handler: ComplexRouteHandler;
|
|
16
|
-
method?: "get" | "post" | "put" | "options";
|
|
17
|
-
}
|
|
18
|
-
export type RouteDefinition = ComplexRouteDefinition | express.RequestHandler;
|
|
19
|
-
export type RouterDefinition = express.Router | RouteDefinition;
|
|
20
|
-
export type RouterWithNullDef = RouterDefinition | null | undefined;
|
|
21
|
-
export interface ComplexStaticDefinition {
|
|
22
|
-
root: string;
|
|
23
|
-
options?: Record<string, unknown>;
|
|
24
|
-
route?: string;
|
|
25
|
-
}
|
|
26
|
-
export type StaticDefinition = ComplexStaticDefinition | string;
|
|
27
|
-
export type UserFromReqFunc = (req: Request) => string | Record<string, unknown> | undefined;
|
|
28
|
-
export interface LogOptions {
|
|
29
|
-
route?: LoggerOptions;
|
|
30
|
-
error?: ErrorLoggerOptions;
|
|
31
|
-
logger?: winston.Logger;
|
|
32
|
-
timestamp?: boolean;
|
|
33
|
-
extraStacktraceFilter?: Array<RegExp> | RegExp;
|
|
34
|
-
ignoredRoutes?: Array<string>;
|
|
35
|
-
/** @deprecated Use `authFromReq` instead */
|
|
36
|
-
userFromReq?: UserFromReqFunc;
|
|
37
|
-
authFromReq?: UserFromReqFunc;
|
|
38
|
-
}
|
|
39
|
-
export interface DefaultErrorHandlerConfig {
|
|
40
|
-
/** Set to true to allow server errors without a code to be sent as-is in the response */
|
|
41
|
-
noErrorFilter?: boolean;
|
|
42
|
-
}
|
|
43
|
-
export interface PipelineSettings {
|
|
44
|
-
topLevels?: Array<RouterWithNullDef>;
|
|
45
|
-
routes?: Array<RouterWithNullDef>;
|
|
46
|
-
statics?: Array<StaticDefinition>;
|
|
47
|
-
postStatics?: Array<RouterWithNullDef>;
|
|
48
|
-
errorHandlers?: Array<express.ErrorRequestHandler>;
|
|
49
|
-
options?: {
|
|
50
|
-
log?: LogOptions;
|
|
51
|
-
middleware?: MiddlewareOptions;
|
|
52
|
-
defaultErrorHandler?: boolean | DefaultErrorHandlerConfig;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export default class PipelineBuilder {
|
|
56
|
-
private _debugLog?;
|
|
57
|
-
constructor(debugLog?: LogFunction);
|
|
58
|
-
private static _addRouterToRouter;
|
|
59
|
-
private static _addMiddlewareToRouter;
|
|
60
|
-
/** Register error handlers
|
|
61
|
-
*
|
|
62
|
-
* @param router
|
|
63
|
-
* @param errorHandlers
|
|
64
|
-
*/
|
|
65
|
-
private static _setErrorHandlers;
|
|
66
|
-
/** Appropriate call to express.static() */
|
|
67
|
-
private static _buildStaticHandler;
|
|
68
|
-
/** See createPipeline() for more info */
|
|
69
|
-
createPipeline({ topLevels, routes, statics, postStatics, errorHandlers, options, }: PipelineSettings): express.Router;
|
|
70
|
-
protected internalLog(...args: Array<string | number | Record<string, string>>): void;
|
|
71
|
-
/** Add generic middlewares to a router
|
|
72
|
-
*
|
|
73
|
-
* @param router
|
|
74
|
-
* @param [middlewareOptions]
|
|
75
|
-
* @param [middlewareOptions.json]
|
|
76
|
-
* Process JSON body
|
|
77
|
-
*/
|
|
78
|
-
private _setGenericMiddlewares;
|
|
79
|
-
private _addRouteToRouter;
|
|
80
|
-
/** Register routes
|
|
81
|
-
*
|
|
82
|
-
* @param router
|
|
83
|
-
* @param routes
|
|
84
|
-
* See routes in createPipeline()
|
|
85
|
-
*/
|
|
86
|
-
private _setRoutes;
|
|
87
|
-
/** Use a static definition */
|
|
88
|
-
private _useComplexStatic;
|
|
89
|
-
/** Define static resources for the express server
|
|
90
|
-
*
|
|
91
|
-
* @param router
|
|
92
|
-
* @param statics
|
|
93
|
-
* See createPipeline()
|
|
94
|
-
*/
|
|
95
|
-
private _setStatics;
|
|
96
|
-
/** Register pre-route loggers
|
|
97
|
-
*
|
|
98
|
-
* @param router
|
|
99
|
-
* @param [logOptions]
|
|
100
|
-
* @param [logOptions.route]
|
|
101
|
-
* Log each route call
|
|
102
|
-
* @param [logOptions.logger]
|
|
103
|
-
*/
|
|
104
|
-
private _setRouteLogger;
|
|
105
|
-
/** Register post-route loggers
|
|
106
|
-
*
|
|
107
|
-
* @param {Router} router
|
|
108
|
-
* @param {object} [logOptions]
|
|
109
|
-
* @param {bool} [logOptions.error]
|
|
110
|
-
* Log each error
|
|
111
|
-
* @param {winstonLogger} [logOptions.logger]
|
|
112
|
-
*/
|
|
113
|
-
private _setErrorLogger;
|
|
114
|
-
private _setDefaultErrorHandler;
|
|
115
|
-
}
|