JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32518
  • Score
    100M100P100Q136247F
  • License MIT

Routing for static site generators, build systems and task runners, heavily based on express.js routes but works with file objects. Used by Assemble, Verb, and Template.

Package Exports

  • en-route

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (en-route) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

en-route NPM version Build Status

Routing for static site generators, build systems and task runners, heavily based on express.js routes but works with file objects. Used by Assemble, Verb, and Template.

Install with npm

$ npm i en-route --save

API

Router

Initialize a new Router with the given options.

Params

  • {Object}: options
  • returns {Router}: which is an callable function

.param

Map the given param placeholder name(s) to the given callback.

Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code, The callback uses the same signature as middleware, the only difference being that the value of the placeholder is passed, in this case the id

of the user. Once the next() function is invoked, just like middleware it will continue on to execute the route, or subsequent parameter functions.

Params

  • name {String}
  • fn {Function}
  • returns {Router} Object: for chaining

Example

app.param('user_id', function(file, next, id) {
  User.find(id, function(err, user) {
    if (err) {
      return next(err);
    } else if (!user) {
      return next(new Error('failed to load user'));
    }
    file.user = user;
    next();
  });
});

.use

Use the given middleware function, with optional path, defaulting to /.

The other difference is that route path is stripped and not visible to the handler function. The main effect of this feature is that mounted handlers can operate without any code changes regardless of the prefix pathname.

Params

  • fn {Function}

Example

var router = new Router();

router.use(function (file, next) {
  false.should.be.true;
  next();
});

.route

Create a new Route for the given path.

Each route contains a separate middleware stack.

See the Route api documentation for details on adding handlers and middleware to routes.

Params

  • path {String}
  • returns {Object} Route: for chaining

.all

Add a handler for all methods to this route.

Behaves just like middleware and can respond or call next to continue processing. You can use multiple .all call to add multiple handlers.

Params

  • handler {Function}
  • returns {Object} Route: for chaining

Example

function checkSomething(file, next) {
  next();
};

function validateUser(file, next) {
  next();
};

route
  .all(validateUser)
  .all(checkSomething)
  .get(function(file, next) {
    file.data.message = "Hello, World!";
  });
  • assemble: Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… more
  • gulp-routes: Add middleware to run for specified routes in your gulp pipeline.
  • template: Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… more
  • verb: Documentation generator for GitHub projects. Extremely powerful, easy to use, can generate anything from API… more

Authors

Jon Schlinkert

Brian Woodward

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.

Based on previous work by: Copyright (c) 2009-2014 TJ Holowaychuk tj@vision-media.ca Copyright (c) 2012-2013 Jared Hanson http://jaredhanson.net/


This file was generated by verb-cli on June 23, 2015.