Update Middleware not firing (why!?!?)

.

This topic has been created from a Discord post (1217621513709162616) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

the test.js in question:

module.exports = (config, { strapi }) => {
  // This is where we add our middleware logic
  return async (ctx, next) => {
    console.log(ctx);
    throw new Error(
      "AJSDJIASDJIOASJIODSSJOAIDJAIOSDJASIODJASODOJIASOJDIASJIoadsjs"
    );
    await next();
  };
};

the “routes/graveinfo.js” in question:

"use strict";

/**
 * graveinfo router
 */

const { createCoreRouter } = require("@strapi/strapi").factories;

module.exports = createCoreRouter("api::graveinfo.graveinfo", {
  config: {
    update: { middlewares: ["api::graveinfo.test"] },
  },
});

put requests made by strapi admin ui

controllers/graveinfo.js

"use strict";

/**
 * graveinfo controller
 */

const { createCoreController } = require("@strapi/strapi").factories;

module.exports = createCoreController(
  "api::graveinfo.graveinfo",
  ({ strapi }) => ({
    async update(ctx) {
      console.log(ctx);
    },
  })
);
``` also not firing! why!? i am pulling my hair out

The controllers/middleware defined here are for handling the API only

Admin calls for this content type will be handled by different middleware/controllers

Could you please tell me which ones are fired by the admin calls?

I can’t recall the paths ATM. But it’s not something you can hook into aside from using a global middleware

(by global middleware I mean a koa one like the request time taken)

ahh, my problem is: after a entry is updated, I need to call some api, the workaround I have, is I have a hook to nextjs when it updates, and nextjs fires the api call, which is super spaghetti code, do you know of a better way to do it?\

Easier way is probably via lifecycle hooks. They trigger for both API and admin calls. See Models | Strapi Documentation

Thank you i will check this out and delete the post when i get home