Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
base-routes
Advanced tools
Readme
Plugin for adding routes support to your
base
application. Requires templates support to work.
(TOC generated by verb using markdown-toc)
Install with npm:
$ npm install --save base-routes
Register the plugin with your base application.
var routes = require('base-routes');
var Base = require('base-app');
var app = new Base();
app.use(routes());
The Router
and Route
classes are on the app
instance, in case they need to be accessed directly.
Example
var router = new app.Router();
var route = new app.Route();
Handle middleware method
for the given file
.
Params
methodName
{String}: Name of the router method to handle.file
{Object}: View objectnext
{Function}: Callback functionreturns
{undefined}Example
app.handle('methodName', file, next);
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(method, file, callback);
// example
app.handleOnce('onLoad', file, callback);
Create a new Route for the given path. Each route contains a separate middleware stack. See the en-route API documentation 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'});
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();
});
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 chainingExample
app.all(/\.hbs$/, function(view, next) {
// do stuff to view
next();
});
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 chainingExample
app.handler('onFoo');
// or
app.handler(['onFoo', 'onBar']);
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 chainingExample
app.handlers(['onFoo', 'onBar', 'onBaz']);
// or
app.handlers('onFoo');
You might also be interested in these projects:
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on August 07, 2017.
FAQs
Plugin for adding routes support to your `base` application. Requires templates support to work.
The npm package base-routes receives a total of 50,147 weekly downloads. As such, base-routes popularity was classified as popular.
We found that base-routes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.