Referencing middlewares inside plugins

System Information
  • Strapi Version : 3.6.2
  • Operating System: Windows 10
  • Node Version: v14


If you have a Strapi plugin and that plugin defines a middleware inside of it. Can I reference that middleware in the load order array?

Example. I have a plugin called custom-plugin with a middleware inside of it. Can I reference it from this configuration:

load: {
    before: [
      'custom-plugin::middleware-inside', <<<<<<<<<------------ IS SOMETHING SIMILAR TO THIS POSSIBLE?
    order: [
      "Define the middlewares' load order by putting their name in this array is the right order",
    after: ['parser', 'router'],

Thank you

This is a great question, one that I’ve actually hit myself while working on prototypes.

From what I understand it’s not natively allowed to modify that specific array in that same structure from within the plugin but you can use the unshift and push methods.

For example I was writing an example plugin to kinda handle audit-logging and you can see here where I was pushing that plugin to the beginning of the array:

I don’t want to modify the order from within the plugin. The plugin itself merely declares a middleware.
I am wondering if the configuration in the actual Strapi project using that plugin (namely the middleware.js) can actually reference the middleware inside that plugin as I show in my example code?

Although perhaps I can use the same technique from the hosting Strapi project inside of the bootstrap function!

Middlewares don’t have a plugin prefix they just have names, those names do need to be unique, I’m not aware of a way to override an existing middleware with one from a plugin (though it might be possible, I’ve just never seen it done)