mirror of
https://github.com/node-red/node-red.git
synced 2025-12-27 15:34:26 +01:00
Do not assume rawBody middleware is last in stack when moving it
This commit is contained in:
@@ -129,8 +129,17 @@ module.exports = function(RED) {
|
||||
if(typeof RED.httpNode === 'function' && (rootApp = getRootApp(RED.httpNode))) {
|
||||
// Add middleware to the stack
|
||||
rootApp.use(rawBodyCapture);
|
||||
// Move the middleware to top of the stack
|
||||
rootApp._router.stack.unshift(rootApp._router.stack.pop());
|
||||
// Find the newly added middleware and move it to the top of the stack
|
||||
// Do not assume its the last entry in the stack as some frameworks (eg loopback)
|
||||
// add middleware in particular orders
|
||||
for (let i = 0; i < rootApp._router.stack.length; i++) {
|
||||
const layer = rootApp._router.stack[i];
|
||||
if (layer && layer.handle === rawBodyCapture) {
|
||||
// Move the middleware to top of the stack
|
||||
rootApp._router.stack.unshift(rootApp._router.stack.splice(i, 1)[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createRequestWrapper(node,req) {
|
||||
|
||||
Reference in New Issue
Block a user