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

connect-pushstate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-pushstate

Connect middleware that rewrites select requests to the site/custom root, thus allowing your pushstate router to handle them

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

connect-pushstate

Connect middleware that rewrites select requests to the site/custom root, thus allowing your pushstate router to handle them.

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.

This functionality is commonly needed by single page webapps such as those developed using frameworks such as Backbone, Ember, Angular, etc.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install connect-pushstate --save

Overview

Load the middleware by adding the following line of JavaScript.

var pushState = require('connect-pushstate/lib/pushstate').pushState;

Add the pushState() middleware call to your server definition, amongst your other middleware. You can customize the root path by passing it in as a parameter. eg) pushState('/somewhere/') Note that connect.static is needed as well in order to actually serve your files.

var connect = require('connect'),
	pushState = require('connect-pushstate/lib/pushstate').pushState
	port = process.env.PORT || 3000

var app = connect()
  .use(connect.logger('dev'))
  .use(pushState())
  .use(connect.static('www/'))
  .listen(port, function() {
    console.log('Application server stated on port', port);
  });

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

# Examples
cd examples
node server.js

# Run Tests
grunt

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 using Grunt.

Release History

  • 0.1.0 Initial release

Keywords

FAQs

Package last updated on 08 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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