backend-manager 5.0.13 → 5.0.15
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
|
@@ -130,8 +130,8 @@ BackendAssistant.prototype.init = function (ref, options) {
|
|
|
130
130
|
// Set ref
|
|
131
131
|
self.ref = {};
|
|
132
132
|
ref = ref || {};
|
|
133
|
-
self.ref.res = ref.res || {};
|
|
134
133
|
self.ref.req = ref.req || {};
|
|
134
|
+
self.ref.res = ref.res || {};
|
|
135
135
|
self.ref.admin = ref.admin || {};
|
|
136
136
|
self.ref.functions = ref.functions || {};
|
|
137
137
|
self.ref.Manager = ref.Manager || {};
|
|
@@ -426,7 +426,7 @@ BackendAssistant.prototype.errorify = function (e, options) {
|
|
|
426
426
|
if (isBetween(options.code, 500, 599)) {
|
|
427
427
|
self.error(newError);
|
|
428
428
|
} else {
|
|
429
|
-
self.log(`⚠️ Client error (${options.code}):`, newError);
|
|
429
|
+
self.log(`⚠️ Client error (${options.code}):`, newError.message, newError.stack);
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
|
package/src/manager/index.js
CHANGED
|
@@ -75,6 +75,12 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
75
75
|
options.logSavePath = typeof options.logSavePath === 'undefined' ? false : options.logSavePath;
|
|
76
76
|
// options.assistant.optionsLogString = options.assistant.optionsLogString || undefined;
|
|
77
77
|
|
|
78
|
+
// Express options
|
|
79
|
+
options.express = options.express || {};
|
|
80
|
+
options.express.bodyParser = options.express.bodyParser || {};
|
|
81
|
+
options.express.bodyParser.json = options.express.bodyParser.json || { limit: '100kb' };
|
|
82
|
+
options.express.bodyParser.urlencoded = options.express.bodyParser.urlencoded || { limit: '100kb', extended: true };
|
|
83
|
+
|
|
78
84
|
// Load libraries
|
|
79
85
|
self.libraries = {
|
|
80
86
|
// Third-party
|
|
@@ -924,20 +930,38 @@ Manager.prototype.setupCustomServer = function (_library, options) {
|
|
|
924
930
|
self.assistant.log('Setting up custom server...');
|
|
925
931
|
}
|
|
926
932
|
|
|
927
|
-
// Setup fastify
|
|
928
|
-
// const app = library({
|
|
929
|
-
// logger: true,
|
|
930
|
-
// // querystringParser: str => querystring.parse(str.toLowerCase())
|
|
931
|
-
// });
|
|
932
|
-
|
|
933
933
|
// Setup express
|
|
934
934
|
const app = require('express')({
|
|
935
935
|
logger: true,
|
|
936
|
-
// querystringParser: str => querystring.parse(str.toLowerCase())
|
|
937
936
|
});
|
|
938
937
|
|
|
939
|
-
// Setup body parser
|
|
940
|
-
app.use(require('body-parser').json());
|
|
938
|
+
// Setup body parser with configurable limits
|
|
939
|
+
app.use(require('body-parser').json(options.express.bodyParser.json));
|
|
940
|
+
app.use(require('body-parser').urlencoded(options.express.bodyParser.urlencoded));
|
|
941
|
+
|
|
942
|
+
// Handle errors with custom error handler
|
|
943
|
+
app.use((err, req, res, next) => {
|
|
944
|
+
// Create a new assistant because our custom Middleware has not been run yet
|
|
945
|
+
const assistant = self.Assistant({ req: req, res: res, }, {});
|
|
946
|
+
|
|
947
|
+
// Handle PayloadTooLargeError from body-parser
|
|
948
|
+
if (err.type === 'entity.too.large') {
|
|
949
|
+
return assistant.respond('Request payload too large.', { code: 413 });
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// Catch-all for other body-parser and middleware errors
|
|
953
|
+
if (err) {
|
|
954
|
+
// Log
|
|
955
|
+
// @TODO: REMOVE THIS LOG ONCE WE'RE CONFIDENT IT'S WORKING AS INTENDED
|
|
956
|
+
console.log('@TODO: Custom Error Handler:', err);
|
|
957
|
+
|
|
958
|
+
// Return
|
|
959
|
+
return assistant.respond(err.message || 'Bad request', { code: err.status || err.code || err.statusCode || 400 });
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// If no error, continue
|
|
963
|
+
next(err);
|
|
964
|
+
});
|
|
941
965
|
|
|
942
966
|
// Designate paths
|
|
943
967
|
const managerRoutesPath = path.normalize(`${__dirname}/routes`);
|