pathologist-middleware
Handling custom static routes since 1967
Last updated 3 years ago by jescalan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pathologist-middleware 
SYNC missed versions from official npm registry.

Pathologist Middleware

npm tests coverage dependencies

Finding the right path since 1967

Why should you care?

Often when building a static app, you want to serve multiple routes with the same static file while keeping the URL structure intact for your app's routing logic. Or perhaps you just want to handle multiple routes for a directory of static files.

Pathologist is an easy to use connect middleware for bringing your single page apps to life. You can define routes with supported globstar matching to serve your static files.

Pathologist simply rewrites the request url to a new static file path. It does not serve the static file for you, so you will need to use your preferred static server middleware with pathologist. We recommend alchemist.

Installation

$ npm install pathologist-middleware --save

Usage

Pathologist accepts an options object which takes globstar-compatible paths as keys and a static file path as values. Routes are matched in the order they are defined in the object. Here's an example that serves an admin client on any URLs starting with /admin, and serves the user client on all other routes.

var http = require('http'),
      connect = require('connect'),
      pathologist = require('pathologist-middleware');

var app = connect().use(
  pathologist({
    '/admin/**/*': '/admin.html',
    '/**': '/index.html'
  })
);

You can also pass a base path to be used with your file path values as the first argument.

var http = require('http'),
    connect = require('connect'),
    path = require('path'),
    pathologist = require('pathologist-middleware');

var app = connect().use(
  pathologist(path.join(__dirname, 'browser'), {
    '/admin/**/*': 'admin.html',
    '/**': 'index.html'
  })
);

Without a base path, the path values passed into pathologist can be either absolute paths, or relative paths from process.cwd().

License & Contributing

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

3 Versions

  • 1.0.0                                ...           3 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.1                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |