connect-pushstate

Requests including a file extension are left untouched so site assets like your images, stylesheets, and JavaScripts will load unaffected, while requests without a file extension, presumably pages or actions within your site, are rewritten to point at the root, with the original URL intact.

You can also specify regular expressions to specifically allow or disallow additional paths from being affected.

allow - A pattern that will allow requests matching it to pass through without being redirected. e.g. pushState({ allow: '^/api' }) You might need this option if your client app and API are on the same server.

disallow - A pattern that will disallow requests matching it to pass through without being redirected. e.g. pushState({ disallow: '^/version/1.2.3' })

'use strict';

var connect =require('connect');

var morgan =require('morgan');

var serveStatic =require('serve-static');

var pushState =require('connect-pushstate');

var port =process.env.PORT||3000;

var app =connect()

.use(pushState())

.use(serveStatic('www/'))

.use(morgan('dev'))

.listen(port,function(){

console.log('Application server stated on port', port);

});

Note that serve-static is needed in order to actually serve your files.

Examples

For a quick demo, see the examples directory, or run the test suite.

cd examples

node server.js

Tests

Execute the test suite

npm test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.