exedra

0.0.12 • Public • Published

Exedra

Routes and functions loader

For example: we have two dirs in a root of our project

/functions
/routes

In /functions we have:

/functions/say.js

/functions/say.js code:

    // ATTENTION! Don't place your code outside export function, You'll not be able to connect with them, code from exports evaled in nodes VM, exedra passing other context into it
    module.exports = function(){
      var fn = {};
      fn.hello = function(){
        return 'hello';
      }
    }

In /routes we have:

/routes/index.js /routes/index/foo.js

/routes/index.js code:

    module.export = function(){
      // We will use this, because it`s express-namespace
      this.get('/bar', function(req, res, next){}); // == 127.0.0.1:3000/bar
    }

Now lets run our hello function from say.js

/routes/index/foo.js code:

    module.exports = function(){
      // Yeah, you could use app instead of this
      app.get('/', function(req, res, next){ // == 127.0.0.1:3000/foo
        res.send(fn.say.hello()); // calling funtcion hello from say.js
      }); 
    }

Ok. Now we need entry point

index.js:

    var express = require('express')
      , Exedra = require('exedra')
      , vs = { foo: 1, bar: 2 }; // This vars will be sended in context of each route/function
      
    var app = vs.app = express.createServer(); // !!!WE NEED TO PASS app INTO vs
    var exedra = new Exedra(vs);

    exedra.functions({ foo: 1 }).routes({ foo: 2 }); // We can extend context
    app.listen();

For more details see /examples/simple-project

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i exedra

    Weekly Downloads

    19

    Version

    0.0.12

    License

    none

    Last publish

    Collaborators

    • corpix