How to write custom route and custom controller into strapi cms application?

System Information
  • Strapi Version: 4.6.2
  • Operating System: Ubuntu
  • Database: Mysql
  • Node Version: 18.0.0
  • NPM Version:
  • Yarn Version:

I looked this Post

I created both custom routes and custom controller
when tried to access custom route in strapi it showing me 404 error

"use strict";
module.exports={
    routes:[
        {
            method:"GET",
            path:"search",
            handler:"custom-controller.getSearch",
            config:{
                policies:[],
            }

        },
        {
            method:"GET",
            path:"check/user",
            handler:"custom-controller.CheckuserExistsORNot",
            config:{
                policies:[],
            }

        }
    ]
}

Custom Controller code

// "use strict";
const { createCoreController } = require('@strapi/strapi').factories;
const modelId="api::question.question"
module.exports=createCoreController(modelId,({strapi})=>({
    async getSearch(ctx){
        try{
            let traceid	= loghandler.createTraceID();

        console.log(traceid,"searching value is:",ctx.request.body);
        const result= await strapi.service(modelId).find(ctx.request.body)
        }
        catch(e){
            console.log(e);
        }
        return "result"
    },
    async CheckuserExistsORNot(ctx){
        let users = await strapi.entityService.findMany(
            "plugin::users-permissions.user", { filters: { email: ctx.params.email }}
          );
          console.log(users,"usersusers",ctx.params.email);
      
          return users.length === 0;
    }
}))
![Screenshot from 2023-05-03 15-34-54|690x388](upload://gmhUAqgf4JppSNtvB9SQpJSXkM.png)

Hey this is probably a silly suggestion. But did you ensure you rebuild/restarted the server.
You can test new routes without complex controllers. Simply hitting the controller would show you the route is working.

Given your custom routing routes, it may be worthwhile exploring this functionality to be a self-contained plugin, you’ll have access to everything you need inside a plugin.