createCoreController Fails in Plugin

System Information
  • Strapi Version:
    4.8.2
  • Operating System:
    Linux Manjaro
  • Database:
    sqlite
  • Node Version:
    16.18.1
  • NPM Version:
    8.19.2

Hi there!

I’m struggling creating a core router for a content-type created in a strapi plugin. I did the following (according to the docs):

// src/plugins/pluginname/server/controllers/foo.js
const { createCoreController } = require("@strapi/strapi").factories;

module.exports = createCoreController("plugin::pluginname.foo", ({ strapi }) =>  ({
  async find(ctx) {
    // This is called
    console.log('find() called');
    // This fails
    const { data, meta } = await super.find(ctx);
    return { data, meta };
  },
}));
//src/plugins/pluginname/server/routes/foo.js
module.exports = {
  type: 'admin',
  routes: [
    {
      method: 'GET',
      path: '/plugin/foo/find',
      handler: 'foo.find',
      config: {
        policies: [],
        auth: false,
        prefix: ""
      },
    }
  ],
};

When I’m calling the http://localhost:1337/plugin/foo/find route, the console logs the message. However the super call fails. I’m quite sure that I’m calling the correct content-type (plugin::pluginname.foo), since when I change this to e.g. plugin::pluginname.bar the server won’t even start.

Help is really very much wanted - thank you a lot! :slight_smile:

PS: I also can’t create a createCoreRoutes, this causes the server to shutdown, prompting “cannot read properties of undefined (reading ‘kind’)”.

Plugins don’t suport createCore you would have to do it in the old way see any of strapis plugins as an example

Thanks you for your response! Do you by chance have a suggestion, which plugin to look at? Would be very helpful! :slight_smile:

I would look at the plugins in strapis mono repo

1 Like