I am trying to set a route. I followed a tutorial. Everything is happening in a folder inside the api folder.
Route folder contains post.js file :
'use strict';
/**
* post router.
*/
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::post.post', {
method: 'GET',
path: '/api/posts/:id/comments',
handler: 'posts.comments'
});
Controllers folder contains an other post.js file :
'use strict';
/**
* post controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::post.post', ({strapi}) => ({
comments: async (ctx) => {
return "Hello"
}
}));
Finally, when I tested URL : http://localhost:1337/api/posts/:id/comments; I have :
{
"data": null,
"error": {
"status": 404,
"name": "NotFoundError",
"message": "Not Found",
"details": {}
}
}
What did I do wrong ? Is something missing ?