// Initialize new yokevaryoke=newYoke();// 1) choose auth adapter; set auth method and key// 2) choose routing adapter// 3) add route(s)// authenticationyoke.useHeaderAuth('some-new-header',someAuthMethod);// http routing adapteryoke.setHTTPAdapter('express');// add routesyoke.addRoutes([{method: 'get',path: '/ping',auth: true,controller: function(cb){/* * this.session = ... * this.body = ... * this.params = ... * this.services = ... */cb(null,'response: pong');}}]);// someLogger.info( /* info stuff */ )// someLogger.Error( /* error stuff */ )// etc...yoke.setLogger(someLogger);// start listening on port 8020 on localhostyoke.start('8020',function(err){console.log('starting... ')});
Dependencies can be initialized and injected like so:
// promiseyoke.inject('PromiseService',PromiseService.then(res=>{/* do stuff */returnres;}));// callbackyoke.inject('CallbackService',callback=>{/* get callback service */callback(null,CallbackService);});// valueyoke.inject('Value',Value);// dependencies are injected into controller scopeyoke.addRoutes([{method: 'get',path: '/ping',controller: function(cb){// use injected dependencies inside controllerthis.services.someInjectedService.doThing(/* do thing */);}}]);// start listeningyoke.start('8020',function(){console.log('starting... ');});