Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-routes

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-routes - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

61

index.js

@@ -7,3 +7,3 @@ 'use strict';

module.exports = function(options) {
return function(app) {
return function baseRoutes(app) {
if (!utils.isValid(app)) return;

@@ -26,2 +26,19 @@

/**
* Lazily initalize `router`, to allow options and custom methods to be
* define after instantiation.
*/
this.define('lazyRouter', function(methods) {
if (typeof this.router === 'undefined') {
this.define('router', new this.Router({
methods: utils.methods
}));
}
if (typeof methods !== 'undefined') {
this.router.method(methods);
}
});
/**
* Handle a middleware `method` for `file`.

@@ -44,3 +61,7 @@ *

if (typeof next !== 'function') {
throw new TypeError('expected callback to be a function');
next = function(err, file) {
app.handleError(method, file, function() {
throw err;
});
};
}

@@ -62,4 +83,4 @@

// if not an instance of `Templates`, or if we're inside a collection
// or the collection is not specified on view.options just handle the route and return
if (!this.isTemplates || !(this.isApp && file.options.collection)) {
// or the collection is not specified on file.options just handle the route and return
if (!this.isTemplates || this.isCollection || !file.options.collection) {
this.router.handle(file, cb);

@@ -94,4 +115,9 @@ return;

if (typeof cb !== 'function') {
throw new TypeError('expected callback to be a function');
cb = function(err, file) {
app.handleError(method, file, function() {
throw err;
});
};
}
if (!file.options.handled) {

@@ -211,2 +237,3 @@ file.options.handled = [];

this.define('all', function(path/*, callback*/) {
this.lazyRouter();
var route = this.route(path);

@@ -234,2 +261,3 @@ route.all.apply(route, [].slice.call(arguments, 1));

this.handlers(method);
return this;
});

@@ -254,29 +282,20 @@

mixinHandlers(methods);
return this;
});
/**
* Lazily initalize `router`, to allow options and custom methods to be
* define after instantiation.
*/
this.define('lazyRouter', function(methods) {
if (typeof this.router !== 'undefined') return;
this.define('router', new this.Router({
methods: utils.methods.concat(methods || [])
}));
});
// Mix router handler methods onto the intance
mixinHandlers(utils.methods);
function mixinHandlers(methods) {
utils.arrayify(methods).forEach(function(method) {
app.define(method, function(path) {
var route = app.route(path);
var route = this.route(path);
var args = [].slice.call(arguments, 1);
route[method].apply(route, args);
return app;
return this;
});
});
}
// Mix router handler methods onto the intance
mixinHandlers(utils.methods);
return baseRoutes;
};
};
{
"name": "base-routes",
"description": "Plugin for adding routes support to your `base` application. Requires templates support to work.",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/node-base/base-routes",

@@ -26,4 +26,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"en-route": "^0.7.5",
"is-registered": "^0.1.3",
"is-valid-instance": "^0.1.0",
"is-valid-app": "^0.1.0",
"lazy-cache": "^2.0.1"

@@ -39,3 +38,8 @@ },

"base",
"routes"
"baseplugin",
"middleware",
"plugin",
"router",
"routes",
"routing"
],

@@ -42,0 +46,0 @@ "verb": {

@@ -13,6 +13,13 @@ 'use strict';

require('en-route', 'router');
require('is-registered');
require('is-valid-instance');
require('is-valid-app');
require = fn;
utils.isValid = function(app) {
if (!utils.isValidApp(app, 'base-routes', ['app', 'collection', 'views', 'list'])) {
return false;
}
debug('loading routes methods');
return true;
};
/**

@@ -41,13 +48,2 @@ * Cast `val` to an array.

utils.isValid = function(app) {
if (!utils.isValidInstance(app, ['app', 'collection', 'views'])) {
return false;
}
if (utils.isRegistered(app, 'base-routes')) {
return false;
}
debug('loading routes methods');
return true;
};
/**

@@ -54,0 +50,0 @@ * Expose `utils` modules

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc