Skip to content

niightly/ike-router

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ike Router

The express router used by Ike.

Ike Router inspires itself a lot on the Rails router and implements some of the basic concepts. You''ll get routes using shorthands, resources and some helpers.

Installation

Install using npm:

$ npm install --save ike-router

Usage

Controllers must be a class (not even a class instance). Ike router instantiates the class and executes a method within it's context.

// CONTROLLER
class SamplesController {
    constructor() {}
    
    index(req, res) {
        let hello = this.helloWorld();
        res.status(200).send(hello);
    }
    
    helloWorld() {
        retunrn 'Hello world';
    }
}

module.exports = SamplesController;

Having controllers like this will make you able to:

// MAIN APP FILE (OR WHATEVER YOU LIKE)
const express = require('express');
const app     = express();
const routes  = require('ike-router')();

routes.get('/', 'samples#index');

app.use('/', routes.draw());
app.listen(3000, () => { console.log('Example running') });

This will boot a simple server, routed by Ike router.

Middleware

Any express-compatible middelware function can be passed to the route with the middleware parameter. It can be a single function or array of functions. It will be executed in the order they are declared, leaving the controller function for last.

Passing middleware:

routes.get('/', 'samples#index', { middleware: someFunc })

Or multiple middlewares, to be executed in the declared order:

routes.get('/', 'samples#index', { middleware: [someFunc, otherFunc] })

Options

You can choose the controllers path when you instantiate the routes object.

...
const routes = require('ike-router')('./controllers/');
...

It will be realtive to where the app.js file is being executed from.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%