Skip to content

CCController

Costa Halicea edited this page Nov 10, 2016 · 1 revision

#CCController Is the base class for every controller in CCD framework It's the place where every get, post put e.t.c handler should be created It is not intended to be used directly but only thru creating classes that inherit it

CCController implements the ICCController interface

interface ICCController {
    //No Override or modifiy, it's the original express router
    router: IRouter; 
    debugSettings?: DebugSettings;
    //this method can be overriden if you like to set custom routes without using decorators
    setRoutes(): void;
    //this method is called from the setRoutes(). if you override this it will be triggered during the controllers initialization
    setDefaultRoutes(...middlewares: RequestHandler[]): IRouter;

    //the transporter method, it handles sending the err/data thru the res object. 
    //override this if you like to have custom logic for sending the resopnses, the default is res.json, or res.sendStatus(500);
    senderFunction(res, err, data):void;

    send(req: any, res: any, data: (err: any, data: any) => any | Object | any): void;
    error(req: any, res: any, data: Object): void;
    proxied(method: any): (req: Request, res: Response, next: NextFunction) => void;
    ctrl(name: string): RequestHandler;
}

Example of creating CCController based class

class HelloCtrl extends CCController{
    @get('/')
    helloWorld(req, res){
        return 'helloWorld' 
    }
}

Clone this wiki locally