@cley_faye/boilerplate 3.21.3 → 4.0.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/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 +22 -29
- 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
|
@@ -1,288 +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
|
-
const express_1 = __importDefault(require("express"));
|
|
33
|
-
const winston_js_1 = require("../winston.js");
|
|
34
|
-
const logger_js_1 = require("./logger.js");
|
|
35
|
-
const unprocessableentityerror_js_1 = require("./unprocessableentityerror.js");
|
|
36
|
-
const getErrorData = (error) => {
|
|
37
|
-
const unprocessable = (0, unprocessableentityerror_js_1.get422Fields)(error);
|
|
38
|
-
if (unprocessable) {
|
|
39
|
-
return {
|
|
40
|
-
message: unprocessable.message,
|
|
41
|
-
extraFields: { fields: unprocessable.fields, errors: unprocessable.errors },
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return error.expose ? { message: error.message } : {};
|
|
45
|
-
};
|
|
46
|
-
const defaultErrorHandler = (errorHandlerConfig) => (err, req, res, next) => {
|
|
47
|
-
const noErrorFilter = typeof errorHandlerConfig === "boolean"
|
|
48
|
-
? false
|
|
49
|
-
: Boolean(errorHandlerConfig.noErrorFilter);
|
|
50
|
-
if (!res.headersSent) {
|
|
51
|
-
if (err.statusCode) {
|
|
52
|
-
const errorData = getErrorData(err);
|
|
53
|
-
const accepted = req.accepts([
|
|
54
|
-
"text",
|
|
55
|
-
"html",
|
|
56
|
-
"json",
|
|
57
|
-
]);
|
|
58
|
-
if (accepted === "json") {
|
|
59
|
-
res.status(err.statusCode).send({
|
|
60
|
-
statusCode: err.statusCode,
|
|
61
|
-
message: errorData.message,
|
|
62
|
-
...errorData.extraFields,
|
|
63
|
-
});
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (errorData.message) {
|
|
67
|
-
res.status(err.statusCode).send(errorData.message);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
res.sendStatus(err.statusCode);
|
|
71
|
-
}
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (!noErrorFilter) {
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
76
|
-
res.status(500).send("An unexpected error occured");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
next(err);
|
|
81
|
-
};
|
|
82
|
-
class PipelineBuilder {
|
|
83
|
-
constructor(debugLog) {
|
|
84
|
-
this._debugLog = debugLog;
|
|
85
|
-
}
|
|
86
|
-
static _addRouterToRouter(baseRouter, newRouter) {
|
|
87
|
-
baseRouter.use(newRouter);
|
|
88
|
-
}
|
|
89
|
-
static _addMiddlewareToRouter(router, middleware) {
|
|
90
|
-
router.use(middleware);
|
|
91
|
-
}
|
|
92
|
-
/** Register error handlers
|
|
93
|
-
*
|
|
94
|
-
* @param router
|
|
95
|
-
* @param errorHandlers
|
|
96
|
-
*/
|
|
97
|
-
static _setErrorHandlers(router, errorHandlers) {
|
|
98
|
-
(errorHandlers ?? []).forEach(errorHandler => {
|
|
99
|
-
router.use(errorHandler);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
/** Appropriate call to express.static() */
|
|
103
|
-
static _buildStaticHandler(staticDef) {
|
|
104
|
-
return typeof staticDef === "string"
|
|
105
|
-
? express_1.default.static(staticDef)
|
|
106
|
-
: express_1.default.static(staticDef.root, staticDef.options);
|
|
107
|
-
}
|
|
108
|
-
/** See createPipeline() for more info */
|
|
109
|
-
createPipeline({ topLevels, routes, statics, postStatics, errorHandlers, options, }) {
|
|
110
|
-
const { middleware, log, defaultErrorHandler: useDefaultErrorHandler } = options ?? {};
|
|
111
|
-
this.internalLog("createPipeline()");
|
|
112
|
-
if (log) {
|
|
113
|
-
const errorConfig = typeof log.error === "boolean"
|
|
114
|
-
? {}
|
|
115
|
-
: log.error ?? {};
|
|
116
|
-
(0, winston_js_1.setConfig)({
|
|
117
|
-
timestamp: log.timestamp ?? false,
|
|
118
|
-
collapseNodeModules: errorConfig.collapseNodeModules ?? true,
|
|
119
|
-
collapseStacktrace: errorConfig.collapseStacktrace ?? true,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
const router = express_1.default.Router();
|
|
123
|
-
this.internalLog("setGenericMiddlewares()");
|
|
124
|
-
this._setGenericMiddlewares(router, middleware);
|
|
125
|
-
this.internalLog("add top level routes/middleware");
|
|
126
|
-
this._setRoutes(router, topLevels);
|
|
127
|
-
this.internalLog("add logger (route call)");
|
|
128
|
-
this._setRouteLogger(router, log);
|
|
129
|
-
this.internalLog("add routes");
|
|
130
|
-
this._setRoutes(router, routes);
|
|
131
|
-
this.internalLog("add statics");
|
|
132
|
-
this._setStatics(router, statics);
|
|
133
|
-
this.internalLog("add post statics routes");
|
|
134
|
-
this._setRoutes(router, postStatics);
|
|
135
|
-
this.internalLog("add logger (errors)");
|
|
136
|
-
this._setErrorLogger(router, log);
|
|
137
|
-
this.internalLog("add error handlers");
|
|
138
|
-
PipelineBuilder._setErrorHandlers(router, errorHandlers);
|
|
139
|
-
this.internalLog("add default error handlers");
|
|
140
|
-
this._setDefaultErrorHandler(router, useDefaultErrorHandler);
|
|
141
|
-
return router;
|
|
142
|
-
}
|
|
143
|
-
internalLog(...args) {
|
|
144
|
-
if (this._debugLog) {
|
|
145
|
-
this._debugLog(...args);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/** Add generic middlewares to a router
|
|
149
|
-
*
|
|
150
|
-
* @param router
|
|
151
|
-
* @param [middlewareOptions]
|
|
152
|
-
* @param [middlewareOptions.json]
|
|
153
|
-
* Process JSON body
|
|
154
|
-
*/
|
|
155
|
-
_setGenericMiddlewares(router, middlewareOptions) {
|
|
156
|
-
const { urlencoded, text, raw, json, } = middlewareOptions ?? {};
|
|
157
|
-
if (urlencoded) {
|
|
158
|
-
this.internalLog("express.urlencoded()");
|
|
159
|
-
const options = urlencoded === true
|
|
160
|
-
? { extended: true }
|
|
161
|
-
: urlencoded;
|
|
162
|
-
router.use(express_1.default.urlencoded(options));
|
|
163
|
-
}
|
|
164
|
-
if (text) {
|
|
165
|
-
this.internalLog("express.text()");
|
|
166
|
-
const options = text === true
|
|
167
|
-
? undefined
|
|
168
|
-
: text;
|
|
169
|
-
router.use(express_1.default.text(options));
|
|
170
|
-
}
|
|
171
|
-
if (raw) {
|
|
172
|
-
this.internalLog("express.raw()");
|
|
173
|
-
const options = raw === true
|
|
174
|
-
? undefined
|
|
175
|
-
: raw;
|
|
176
|
-
router.use(express_1.default.raw(options));
|
|
177
|
-
}
|
|
178
|
-
if (json) {
|
|
179
|
-
this.internalLog("express.json()");
|
|
180
|
-
const options = json === true
|
|
181
|
-
? undefined
|
|
182
|
-
: json;
|
|
183
|
-
router.use(express_1.default.json(options));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
_addRouteToRouter(router, route) {
|
|
187
|
-
const method = route.method ?? "get";
|
|
188
|
-
this.internalLog(`Adding route "${route.route}" [${method}]`);
|
|
189
|
-
// Simple route definition
|
|
190
|
-
if (Array.isArray(route.handler)) {
|
|
191
|
-
// Multiple handlers for same route
|
|
192
|
-
route.handler.forEach(handler => router[method](route.route, handler));
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
// Simple handler
|
|
196
|
-
router[method](route.route, route.handler);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/** Register routes
|
|
200
|
-
*
|
|
201
|
-
* @param router
|
|
202
|
-
* @param routes
|
|
203
|
-
* See routes in createPipeline()
|
|
204
|
-
*/
|
|
205
|
-
_setRoutes(router, routes) {
|
|
206
|
-
(routes ?? []).filter((e) => Boolean(e)).forEach(routeDef => {
|
|
207
|
-
const asRouter = routeDef;
|
|
208
|
-
const asRouteDef = routeDef;
|
|
209
|
-
const asRequestHandler = routeDef;
|
|
210
|
-
if (asRouter.name === "router") {
|
|
211
|
-
// Raw router
|
|
212
|
-
this.internalLog("Adding raw router");
|
|
213
|
-
PipelineBuilder._addRouterToRouter(router, asRouter);
|
|
214
|
-
}
|
|
215
|
-
else if (asRouteDef.route) {
|
|
216
|
-
// Specific routes
|
|
217
|
-
this._addRouteToRouter(router, asRouteDef);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
// Middleware
|
|
221
|
-
this.internalLog("Adding middleware");
|
|
222
|
-
PipelineBuilder._addMiddlewareToRouter(router, asRequestHandler);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
/** Use a static definition */
|
|
227
|
-
_useComplexStatic(router, staticDef) {
|
|
228
|
-
const staticHandler = PipelineBuilder._buildStaticHandler(staticDef);
|
|
229
|
-
if (typeof staticDef === "string") {
|
|
230
|
-
this.internalLog("Adding statics");
|
|
231
|
-
router.use(staticHandler);
|
|
232
|
-
}
|
|
233
|
-
else if (staticDef.route) {
|
|
234
|
-
this.internalLog(`Adding statics for route "${staticDef.route}"`);
|
|
235
|
-
router.use(staticDef.route, staticHandler);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
this.internalLog("Adding statics");
|
|
239
|
-
router.use(staticHandler);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/** Define static resources for the express server
|
|
243
|
-
*
|
|
244
|
-
* @param router
|
|
245
|
-
* @param statics
|
|
246
|
-
* See createPipeline()
|
|
247
|
-
*/
|
|
248
|
-
_setStatics(router, statics) {
|
|
249
|
-
(statics ?? []).forEach(staticDef => this._useComplexStatic(router, staticDef));
|
|
250
|
-
}
|
|
251
|
-
/** Register pre-route loggers
|
|
252
|
-
*
|
|
253
|
-
* @param router
|
|
254
|
-
* @param [logOptions]
|
|
255
|
-
* @param [logOptions.route]
|
|
256
|
-
* Log each route call
|
|
257
|
-
* @param [logOptions.logger]
|
|
258
|
-
*/
|
|
259
|
-
_setRouteLogger(router, logOptions) {
|
|
260
|
-
const { route } = logOptions ?? {};
|
|
261
|
-
if (route) {
|
|
262
|
-
this.internalLog("Adding route logger");
|
|
263
|
-
(0, logger_js_1.registerRouteLogger)(router, logOptions);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
/** Register post-route loggers
|
|
267
|
-
*
|
|
268
|
-
* @param {Router} router
|
|
269
|
-
* @param {object} [logOptions]
|
|
270
|
-
* @param {bool} [logOptions.error]
|
|
271
|
-
* Log each error
|
|
272
|
-
* @param {winstonLogger} [logOptions.logger]
|
|
273
|
-
*/
|
|
274
|
-
_setErrorLogger(router, logOptions) {
|
|
275
|
-
const { error } = logOptions ?? {};
|
|
276
|
-
if (error) {
|
|
277
|
-
this.internalLog("Adding error logger");
|
|
278
|
-
(0, logger_js_1.registerErrorLogger)(router, logOptions);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
_setDefaultErrorHandler(router, defaultErrorHandlerConfig) {
|
|
282
|
-
if (defaultErrorHandlerConfig) {
|
|
283
|
-
this.internalLog("Adding default error handler");
|
|
284
|
-
router.use(defaultErrorHandler(defaultErrorHandlerConfig));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
exports.default = PipelineBuilder;
|
|
@@ -1,57 +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.get422Fields = void 0;
|
|
30
|
-
const UNPROCESSABLE_ENTITY = 422;
|
|
31
|
-
const get422Fields = (error) => {
|
|
32
|
-
const { statusCode, cause, fields } = error;
|
|
33
|
-
if (statusCode !== UNPROCESSABLE_ENTITY
|
|
34
|
-
|| !cause
|
|
35
|
-
|| !Array.isArray(cause)
|
|
36
|
-
|| !fields
|
|
37
|
-
|| !Array.isArray(fields)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
let fieldsStr;
|
|
41
|
-
try {
|
|
42
|
-
fieldsStr = JSON.stringify(fields);
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
fieldsStr = "<error>";
|
|
46
|
-
}
|
|
47
|
-
let errorsStr;
|
|
48
|
-
try {
|
|
49
|
-
errorsStr = JSON.stringify(cause);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
errorsStr = "<error>";
|
|
53
|
-
}
|
|
54
|
-
const message = `${error.message}: fields=${fieldsStr}, errors=${errorsStr}`;
|
|
55
|
-
return { message, fields, errors: cause };
|
|
56
|
-
};
|
|
57
|
-
exports.get422Fields = get422Fields;
|
package/lib/express.d.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { Server } from "net";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import winston from "winston";
|
|
4
|
-
import { PipelineSettings, LogFunction } from "./express/pipelinebuilder.js";
|
|
5
|
-
/** Create the full processing pipeline for an Express server
|
|
6
|
-
*
|
|
7
|
-
* This function creates a pipeline this way:
|
|
8
|
-
* - Pass generic middlewares (see options)
|
|
9
|
-
* - Pass custom top-level middlewares
|
|
10
|
-
* - Pass logging middleware (see options)
|
|
11
|
-
* - Pass routes
|
|
12
|
-
* - Pass error logging middleware (see options)
|
|
13
|
-
* - Pass error handlers
|
|
14
|
-
* - Fallback to a default error handler (see below)
|
|
15
|
-
*
|
|
16
|
-
* The default error handler is a layer above the express default error
|
|
17
|
-
* handler.
|
|
18
|
-
* If it is reached, it will check if the error object looks like an
|
|
19
|
-
* http-errors exception, and if that's the case, send the error code and the
|
|
20
|
-
* message (if applicable).
|
|
21
|
-
* If the request accepts json, a json object with the error is returned.
|
|
22
|
-
* Otherwise text is returned.
|
|
23
|
-
*
|
|
24
|
-
* For convenience, providing timestamp and collapseNodeModules here will automatically
|
|
25
|
-
* update the basic consoleLogger configuration.
|
|
26
|
-
*
|
|
27
|
-
* @param settings
|
|
28
|
-
*
|
|
29
|
-
* @param [settings.topLevels]
|
|
30
|
-
* List top-level middlewares. See routes.
|
|
31
|
-
*
|
|
32
|
-
* @param [settings.routes]
|
|
33
|
-
* List routes and routers.
|
|
34
|
-
* For each router and function, a simple "use()" call is used.
|
|
35
|
-
* If an object is provided, it must have two properties:
|
|
36
|
-
* - route: the actual route to listen to
|
|
37
|
-
* - handler: either a function, a router, or an array of functions that will
|
|
38
|
-
* be called in sequence on this request.
|
|
39
|
-
* - method: the method ("get", "post", "put", "options"). If missing,
|
|
40
|
-
* default to "get".
|
|
41
|
-
*
|
|
42
|
-
* @param [settings.statics]
|
|
43
|
-
* List of directory to serve as static content.
|
|
44
|
-
* Can be either a string (the path) or an object with the following
|
|
45
|
-
* properties:
|
|
46
|
-
* - root: the root in the filesystem for this static provider
|
|
47
|
-
* - options: (optional) the options to pass to static()
|
|
48
|
-
* - route: (optional) the route where the static resources will be served
|
|
49
|
-
*
|
|
50
|
-
* @param [settings.postStatics]
|
|
51
|
-
* Register routes handled after statics. See routes.
|
|
52
|
-
*
|
|
53
|
-
* @param [settings.errorHandlers]
|
|
54
|
-
* Process errors. Must be function with four parameters.
|
|
55
|
-
*
|
|
56
|
-
* @param [settings.options]
|
|
57
|
-
* @param [settings.options.log]
|
|
58
|
-
* @param [settings.options.log.route]
|
|
59
|
-
* Log each route. Can be an object with all properties expected from
|
|
60
|
-
* winston-express.logger()
|
|
61
|
-
*
|
|
62
|
-
* @param [settings.options.log.error]
|
|
63
|
-
* Log error content. Can be either a boolean or an object with the
|
|
64
|
-
* "collapseNodeModules" property. The error log will then display a truncated
|
|
65
|
-
* stacktrace where lines containing node_modules are removed.
|
|
66
|
-
*
|
|
67
|
-
* @param [settings.options.log.timestamp]
|
|
68
|
-
* Log timestamps on each lines
|
|
69
|
-
*
|
|
70
|
-
* @param [settings.options.log.logger]
|
|
71
|
-
* An existing winston logger to use. Only the transport will be used.
|
|
72
|
-
*
|
|
73
|
-
* @param [settings.options.middleware]
|
|
74
|
-
* @param [settings.options.middleware.urlencoded]
|
|
75
|
-
* Parse URL encoded requests. Can be true or settings for urlencoded().
|
|
76
|
-
* Default to handling application/x-www-form-urlencoded.
|
|
77
|
-
*
|
|
78
|
-
* @param [settings.options.middleware.text]
|
|
79
|
-
* Parse raw text body requests. Can be true or settings for text()
|
|
80
|
-
* Default to handling text/plain
|
|
81
|
-
*
|
|
82
|
-
* @param [settings.options.middleware.raw]
|
|
83
|
-
* Parse raw body requests into an arraybuffer. Can be true or settings for
|
|
84
|
-
* raw()
|
|
85
|
-
* Default to handling application/octet-stream
|
|
86
|
-
*
|
|
87
|
-
* @param [settings.options.middleware.json]
|
|
88
|
-
* Parse JSON body requests. Can be true or settings for json()
|
|
89
|
-
* Default to handling application/json
|
|
90
|
-
*
|
|
91
|
-
* @param [settings.options.defaultErrorHandler]
|
|
92
|
-
* Setup the default error handler. Defaults to false.
|
|
93
|
-
*
|
|
94
|
-
* @param [debugLog]
|
|
95
|
-
* Function to log debug informations
|
|
96
|
-
*
|
|
97
|
-
* @return
|
|
98
|
-
* The returned object can be used
|
|
99
|
-
*/
|
|
100
|
-
export declare const createPipeline: (settings: PipelineSettings, debugLog?: LogFunction) => express.Router;
|
|
101
|
-
/**
|
|
102
|
-
* Configure the views rendering engine for an ExpressJS App
|
|
103
|
-
*/
|
|
104
|
-
export declare const setViewEngine: (app: express.Express, viewEngine: string, viewsDirectory: string, extraLocals?: Record<string, string | number>) => void;
|
|
105
|
-
/**
|
|
106
|
-
* Function to call when the server stops.
|
|
107
|
-
*
|
|
108
|
-
* This is usually triggered by a SIGTERM.
|
|
109
|
-
*
|
|
110
|
-
* If the function returns "true", it prevent the process from stopping.
|
|
111
|
-
* Otherwise `process.exit()` is called.
|
|
112
|
-
*/
|
|
113
|
-
type ShutdownFunction = () => Promise<boolean | undefined> | boolean | undefined;
|
|
114
|
-
export interface StartDefinition {
|
|
115
|
-
app: express.Application;
|
|
116
|
-
/** @deprecated use listenInterface instead */
|
|
117
|
-
allowNonLocal?: boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Which interface to listen on.
|
|
120
|
-
*
|
|
121
|
-
* Defaults to `false` which means listen only on localhost.
|
|
122
|
-
* Set to `true` to listen on all interfaces
|
|
123
|
-
* Set to an IP to bind on a specific interface.
|
|
124
|
-
*/
|
|
125
|
-
listenInterface?: boolean | string;
|
|
126
|
-
port?: number;
|
|
127
|
-
shutdownFunction?: ShutdownFunction;
|
|
128
|
-
logger?: winston.Logger;
|
|
129
|
-
noReady?: boolean;
|
|
130
|
-
}
|
|
131
|
-
export interface StartResult {
|
|
132
|
-
port: number;
|
|
133
|
-
server: Server;
|
|
134
|
-
}
|
|
135
|
-
/** Start the server and register signal for automatic closing.
|
|
136
|
-
*
|
|
137
|
-
* @param app
|
|
138
|
-
* @param [allowNonLocal]
|
|
139
|
-
* Allow requests from outside of localhost
|
|
140
|
-
*
|
|
141
|
-
* @param [port]
|
|
142
|
-
* Port to listen from. Default to a random available port.
|
|
143
|
-
*
|
|
144
|
-
* @param [shutdownFunction]
|
|
145
|
-
* Function to call after the server is shutdown (all connection closed)
|
|
146
|
-
*
|
|
147
|
-
* @param [logger]
|
|
148
|
-
*
|
|
149
|
-
* @return
|
|
150
|
-
* @property port
|
|
151
|
-
* The port the server is listening on
|
|
152
|
-
*
|
|
153
|
-
* @property server
|
|
154
|
-
*/
|
|
155
|
-
export declare const appStart: ({ app, allowNonLocal, listenInterface, port, shutdownFunction, logger, noReady, }: StartDefinition) => Promise<StartResult>;
|
|
156
|
-
export {};
|