
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
connect-pushstate
Advanced tools
Connect middleware that rewrites select requests to the site/custom root, thus allowing your pushstate router to handle them
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.
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
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
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.
FAQs
Connect middleware that rewrites select requests to the site root, allowing your client-side pushstate router to handle them
The npm package connect-pushstate receives a total of 5,477 weekly downloads. As such, connect-pushstate popularity was classified as popular.
We found that connect-pushstate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.