Backend hook n8n.ready with app.use(...) is not working

This is my hook js file:

module.exports = {
      n8n: {
        ready: [
          async function ({ app }, config) {
            console.log('Running ready hook');            
            app.use(async (req, res, next) => {
                console.log('I am in middleware');
            });
          },
        ],
      },
    };

But it never steps into the middleware function. The line console.log('I am in middleware'); is never reached. However, the line console.log('Running ready hook'); is reached.

My intention is to use the middleware to create a cookie when n8n starts. Can anybody help?

Information on your n8n setup

  • n8n version: 1.104.1
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Kubernetes
  • Operating system: Ubuntu]

The n8n.ready hook executes correctly, but it cannot be used to inject middleware into the internal n8n router. There is currently no native hook that allows intercepting internal HTTP requests at earlier initialization stages. To achieve effects such as injecting cookies, headers, or global validations, it is best to use an external proxy. For custom logic, Webhook nodes within n8n are still the best way to expose controllable endpoints.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.