Custom route always 404 on GET method

System Information
  • Strapi Version: 5.0.0-rc3
  • Operating System: macos 12.5.1
  • Database: mariadb
  • Node Version: 18.19.0
  • NPM Version: 10.8.2

Hi,
I am trying to create a custom route like this:

export default {
  routes: [
    {
      method: 'GET',
      path: '/commands/get-points',
      handler: 'command.getPoints',
    },
  ],
}

Here is my controller:

import { factories } from '@strapi/strapi'

export default factories.createCoreController('api::command.command', ({ strapi }) => ({
  async getPoints() {
    return "henlo"
  },
}))

I enabled public access as you can see on this screenshot.

But this route always gives me a 404 response. On the contrary, when I use another HTTP method, it works: for example when setting the method to POST, this works.
→ the GET method is the problem.

I have other custom routes on GET method that just work, but on this object it does not. Why is it behaving like that ?

I have found the solution, which is a weird behaviour:

The routes seem to be loaded for each file located in /routes for a particular object, in an alphabetical order. My order is:

/routes
    command.ts
    custom-routes.ts

So I guess the core routes are first loaded, and then my custom routes defined in custom-routes.ts. I don’t understand why, but my GET route defined in custom-routes.ts is replaced by the findOne route.

When I change the order of the files to be something like this:

/routes
    a-custom-routes.ts
    command.ts

Then my custom route is recognized and works. I can’t explain why this is behaving like this, but here it is. So it seems that the general rule would be to always have one’s custom routes file before the core file ones.