npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

This package has been deprecated

Author message:

Is not maintained

specla-router

0.0.6 • Public • Published

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;

Keywords

install

npm i specla-router

Downloadsweekly downloads

14

version

0.0.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability