Custom Controller fail & Random Sort Plugin - CORS error

System Information
  • Strapi Version: v4.4.1
  • Operating System: Windows 10
  • Node Version: 16.18.1

Hello! I’m trying to get X random entries from my API for a quiz app. I tried to make a simple custom controller, just to test, but the response is always 404 and I don’t know why. My idea was to shuffle the array of entries, then slice it and return it. I already do that on the frontend, but I figured out it would be better if I do it on the backend because I have quizzes with over 1k questions.

My route:

module.exports = {
  routes: [
    { method: "GET", path: "categoria-a/random", handler: "random.index" },

My controller:

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

module.exports = createCoreController("api::categoria-a.categoria-a", () => ({
  async index(ctx, next) {
    ctx.body = "Random";

Also, I tried to use the Random Sort plugin just for the randomize part. It works well using postman, but when I make my axios request on the frontend it gives me CORS Error, Acces-Control-Allow-Origin. It throws that error only when I use ?randomSort route.

    name: "strapi::cors",
    config: {
      enabled: true,
      headers: "*",
      origin: ["http://localhost:1337"],

If you’re attempting to do a cross-origin request from within a content script, it will be blocked by Chrome regardless of permissions.