Socket
Socket
Sign inDemoInstall

base-routes

Package Overview
Dependencies
23
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    base-routes

Plugin for adding routes support to your `base` application. Requires templates support to work.


Version published
Maintainers
1
Install size
289 kB
Created

Readme

Source

base-routes NPM version NPM downloads Build Status

Plugin for adding routes support to your base application. Requires templates support to work.

TOC

Install

Install with npm:

$ npm install base-routes --save

Usage

var routes = require('base-routes');
var Base = require('base-app');

var app = new Base();
app.use(routes());

API

Example

var router = new app.Router();
var route = new app.Route();

.handle

Handle a middleware method for file.

Params

  • method {String}: Name of the router method to handle. See router methods
  • file {Object}: View object
  • callback {Function}: Callback function
  • returns {undefined}

Example

app.handle('customMethod', file, callback);

.handleOnce

Run the given middleware handler only if the file has not already been handled by method.

Params

  • method {Object}: The name of the handler method to call.
  • file {Object}
  • returns {undefined}

Example

app.handleOnce('onLoad', file, callback);

.route

Create a new Route for the given path. Each route contains a separate middleware stack. See the [route API documentation][route-api] for details on adding handlers and middleware to routes.

Params

  • path {String}
  • returns {Object}: Returns the instance for chaining.

Example

app.create('posts');
app.route(/blog/)
  .all(function(file, next) {
    // do something with file
    next();
  });

app.post('whatever', {path: 'blog/foo.bar', content: 'bar baz'});

.param

Add callback triggers to route parameters, where name is the name of the parameter and fn is the callback function.

Params

  • name {String}
  • fn {Function}
  • returns {Object}: Returns the instance for chaining.

Example

app.param('title', function(view, next, title) {
  //=> title === 'foo.js'
  next();
});

app.onLoad('/blog/:title', function(view, next) {
  //=> view.path === '/blog/foo.js'
  next();
});

.all

Special route method that works just like the router.METHOD() methods, except that it matches all verbs.

Params

  • path {String}
  • callback {Function}
  • returns {Object} this: for chaining

Example

app.all(/\.hbs$/, function(view, next) {
  // do stuff to view
  next();
});

.handler

Add a router handler method to the instance. Interchangeable with the handlers method.

Params

  • method {String}: Name of the handler method to define.
  • returns {Object}: Returns the instance for chaining

Example

app.handler('onFoo');
// or
app.handler(['onFoo', 'onBar']);

.handlers

Add one or more router handler methods to the instance.

Params

  • methods {Array|String}: One or more method names to define.
  • returns {Object}: Returns the instance for chaining

Example

app.handlers(['onFoo', 'onBar', 'onBaz']);
// or
app.handlers('onFoo');

You might also be interested in these projects:

  • base-option: Adds a few options methods to base, like option, enable and disable. See the readme… more | homepage
  • base-plugins: Upgrade's plugin support in base applications to allow plugins to be called any time after… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • en-route: Routing for static site generators, build systems and task runners, heavily based on express.js routes… more | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine.… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on May 17, 2016.

Keywords

FAQs

Last updated on 17 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc