Package Exports
- hygienist-middleware
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 (hygienist-middleware) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Hygienist Middleware
Providing clean urls for static sites since 1776
Note: This project is in early development, and versioning is a little different. Read this for more details.
Why should you care?
Let's say that you are using connect to serve a static site. You might have pages like about.html
, foobar.html
, etc. When using connect's default static router, you'll see the full .html
extension at the end of each of these pages. But really, that's not necessary for the user to see or have to type in, it would be better to go to http://example.com/about
than http://example.com/about.html
. This is exactly what hygienist does -- it removes the file extensions and just uses the filename as the route. How convenient!
Installation
npm install hygienist-middleware --save
Usage
This library can be used with connect, express, and any other server stack that accepts the same middleware format. A very basic usage example:
var http = require('http');
connect = require('connect'),
hygienist = require('hygienist-middleware');
var app = connect().use(hygienist('public'));
var server = http.createServer(app).listen(1111)
Hygienist directly extends serve-static, the default static router in connect and express, so it also acts as a full static file server. Any arguments that you can pass to serve-static, you can also pass to hygienist, and they will work as expected.
By default, hygienist will only serve .html
files as clean urls. If you would like to change this behavior, you can override via a clean
option, which is a globstar string or array of globstar strings intended to match files you want hygienist to serve as clean urls. For example, if we wanted to serve both html and json files with clean urls:
hygienist('public', { clean: ['*.html', '*.json'] })
That's it! If you have other ideas or ways you'd like to use hygienist, we'd love to hear them, just open an issue or pull request!
License & Contributing
- Details on the license can be found here
- Details on running tests and contributing can be found here