System Information
- Strapi Version: 4.1.11
- Operating System: Centos 7
- Database: MariaDB 10.2.43
- Node Version: node v16.15.0
- NPM Version: npm 8.5.5
I am trying to set slug like in video How to replace the Strapi ID field with a slug field - YouTube
my /src/api/movie/controllers/movie.js
'use strict';
/**
* movie controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::movie.movie', ({ strapi }) => ({
// Method 3: Replacing a core action
async findOne(ctx) {
const { id } = ctx.params;
const entity = await strapi.db.query('api::movie.movie').findOne({
where: { slug: id }
});
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return this.transformResponse(sanitizedEntity);
}
}));
/src/api/movie/routes/custom.js
module.exports = {
routes: [
{
method: 'GET',
path: '/movies/:slug',
handler: 'movie.findOne',
config: {
auth:false,
}
}
]
}
/src/api/movie/routes/movie.js
'use strict';
/**
* movie router.
*/
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::movie.movie');
Fresh installation, movie with slug batman-2022 added but still on request
/api/movies/batman-2022
I have get
{
"data": null,
"error": {
"status": 404,
"name": "NotFoundError",
"message": "Not Found",
"details": {}
}
}