How can I create a route on Strapi?

Viewed 109

I am trying to create a route on Strapi in order to get comments from one article.

https://docs.strapi.io/developer-docs/latest/development/backend-customization/routes.html#configuring-core-routers

The solution proposes to create a route in an existing file in routes folder itself in api folder. I am thinking I made a mistake with syntax but even with the help in the documentation. I don't find the solution.

'use strict';

/**
 * post router.
 */

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

module.exports = createCoreRouter('api::post.post', {
    only: ['find'],
    config: {
        find: {
          auth: false,
          policies: [],
          middlewares: [],
        }
    },
    method: "GET",
    path: "/posts/:id/comments",
    handler: "posts.comments"
});

Here is the datas from API we can see in my article :

Post datas

Thank you very much for your help.

0 Answers
Related