0.7.0 • Published 10 years ago

sugar-boot v0.7.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

sugar-boot is an little express bootstrap managing dependency injections and routes directly inside of classes.

Current status

Alpha version, creation on 18/09/15. There will be more in the near future.

Should be used with es6 babel

How it works

The sugar-boot module will look inside of a dist folder, to find components and routers. It then add them inside of an injector through di-injector and manage the application through this.

It's just an alpha, but feel free to try it and to me a feedback :-).

#Creation of a controller, Billing for example :

class Billing{
  constructor(billingService){
    this.billingService = billingService;
  }

  getAll(req, res){
    res.send(this.billingService.getAll());
  }
}


/* Allow Billing class to be injected or to inject some other objects */
Billing.Component = true;

/* Require an instance of BillingService in the constructor, based on di-injector external module */
Billing.diConstructor = ['BillingService'];

/* Tell /path with the concerned verb and the callback method (of the current class) */
Billing.Routes = [
  {verb:'get', path:'/billings', callback:'getAll'}
];

export default Billing;

#Creation of a service like this BillingService :

class BillingService{

 getAll(){
   return [{id:1,title:"First billing"},{id:2,title:"Second billing"}];
 }
}

/* Allow BillingService class to be injected or to inject some other objects */
BillingService.Component = true;
export default BillingService;

#Creation of the application

The default one :

/* Require the sugar-boot */
var boot = require('sugar-boot');

/* Boot the express server and watch inside of the dist folder to find components or routers */
boot.runFrom('./dist',['']).then(function(server){
 /* start the server on which port you need */
 server.start(8010);
});

The most advanced one :

/* Require the sugar-boot */
var boot = require('sugar-boot');

/* Binding librairie for external injection */
var binding = require('di-injector').Binding;

/* Boot the express server and watch inside of the dist folder to find components or routers, except in the dist/repo-not-needed */
boot.runFrom('./dist', ['!dist/repo-not-needed'],[
 new Binding('MyDatabaseAccess',{toValue:mongoInstance}) // Allow you to make something like diConstructor = ['MyDatabaseAccess'] inside of a component (Component = true)
]).then(function(server){

 /* Use callback before routing*/
 server.expressInstance.use(path,middlewareCallback);

 /* start the server on which port you need */
 server.start(8010);
});
0.7.0

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.10

10 years ago

0.0.1

10 years ago