diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js index 4cbf03f39..d6f766c01 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js @@ -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) {