mastercontroller 1.3.31 → 1.3.32
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/MasterControl.js +38 -31
- package/package.json +1 -1
package/MasterControl.js
CHANGED
|
@@ -957,37 +957,9 @@ class MasterControl {
|
|
|
957
957
|
await next();
|
|
958
958
|
});
|
|
959
959
|
|
|
960
|
-
// 5. Routing (
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
// config/load creates a new requestObject without copying ctx.state
|
|
964
|
-
ctx.request.__pipelineState = ctx.state;
|
|
965
|
-
// Load config/load which triggers routing
|
|
966
|
-
require(`${$that.root}/config/load`)(ctx);
|
|
967
|
-
});
|
|
968
|
-
|
|
969
|
-
// 6. Global Error Handler
|
|
970
|
-
$that.pipeline.useError(async (error, ctx, next) => {
|
|
971
|
-
logger.error({
|
|
972
|
-
code: 'MC_ERR_PIPELINE',
|
|
973
|
-
message: 'Error in middleware pipeline',
|
|
974
|
-
error: error.message,
|
|
975
|
-
stack: error.stack,
|
|
976
|
-
path: ctx.request.url,
|
|
977
|
-
method: ctx.type
|
|
978
|
-
});
|
|
979
|
-
|
|
980
|
-
if (!ctx.response.headersSent) {
|
|
981
|
-
ctx.response.statusCode = 500;
|
|
982
|
-
ctx.response.setHeader('Content-Type', 'application/json');
|
|
983
|
-
ctx.response.end(JSON.stringify({
|
|
984
|
-
error: 'Internal Server Error',
|
|
985
|
-
message: process.env.NODE_ENV === 'production'
|
|
986
|
-
? 'An error occurred'
|
|
987
|
-
: error.message
|
|
988
|
-
}));
|
|
989
|
-
}
|
|
990
|
-
});
|
|
960
|
+
// 5. Routing and Error Handler are registered in start() so that user
|
|
961
|
+
// middleware (auth, logging, etc.) registered between setupServer() and
|
|
962
|
+
// start() runs BEFORE the terminal routing middleware.
|
|
991
963
|
}
|
|
992
964
|
|
|
993
965
|
async serverRun(req, res){
|
|
@@ -1031,6 +1003,41 @@ class MasterControl {
|
|
|
1031
1003
|
this.serverSettings(this._pendingServerSettings);
|
|
1032
1004
|
this._pendingServerSettings = null;
|
|
1033
1005
|
}
|
|
1006
|
+
|
|
1007
|
+
// Register terminal routing and error handler LAST so that user middleware
|
|
1008
|
+
// (auth, logging, etc.) registered between setupServer() and start() runs first
|
|
1009
|
+
const $that = this;
|
|
1010
|
+
|
|
1011
|
+
// Terminal routing middleware
|
|
1012
|
+
$that.pipeline.run(async (ctx) => {
|
|
1013
|
+
// Attach pipeline state to raw request object so it survives even if
|
|
1014
|
+
// config/load creates a new requestObject without copying ctx.state
|
|
1015
|
+
ctx.request.__pipelineState = ctx.state;
|
|
1016
|
+
require(`${$that.root}/config/load`)(ctx);
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
// Global error handler
|
|
1020
|
+
$that.pipeline.useError(async (error, ctx, next) => {
|
|
1021
|
+
logger.error({
|
|
1022
|
+
code: 'MC_ERR_PIPELINE',
|
|
1023
|
+
message: 'Error in middleware pipeline',
|
|
1024
|
+
error: error.message,
|
|
1025
|
+
stack: error.stack,
|
|
1026
|
+
path: ctx.request.url,
|
|
1027
|
+
method: ctx.type
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
if (!ctx.response.headersSent) {
|
|
1031
|
+
ctx.response.statusCode = 500;
|
|
1032
|
+
ctx.response.setHeader('Content-Type', 'application/json');
|
|
1033
|
+
ctx.response.end(JSON.stringify({
|
|
1034
|
+
error: 'Internal Server Error',
|
|
1035
|
+
message: process.env.NODE_ENV === 'production'
|
|
1036
|
+
? 'An error occurred'
|
|
1037
|
+
: error.message
|
|
1038
|
+
}));
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1034
1041
|
}
|
|
1035
1042
|
|
|
1036
1043
|
startMVC(foldername){
|
package/package.json
CHANGED