0.0.6 • Published 7 years ago

specla-router v0.0.6

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

Specla Router

npm version Build Status

This is the routing module for the Specla Framework. Its a wrapper on top of the express router and it enables you to specify a path to the folder where your controllers are located. The goal of this module is to make it easier to include your controllers for your application.

Install

npm install specla-router --save

Setup

const Router = require('specla-router');
const express = require('express');
const app = express();

const router = new Router(app, {
  path: __dirname+'/api/controllers'
});

// basic route to a controller action
router.get('/', 'Controller.action');

// route with middleware
router.get('/authenticated', [authenticated], 'Controller.action');

app.listen(3000);

Controllers

The example below is the boilerplate code for a Controller. The class contuctor will work as a middleware function.

class Controller {

  constructor(req, res){
    // Do something before the action is triggered
  }

  action(req, res){
    res.send('Controller action!');
  }
}

module.exports = Controller;
0.0.6

7 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago