Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
connect-pushstate
Advanced tools
Connect middleware that rewrites select requests to the site root, allowing your client-side pushstate router to handle them
Connect middleware that rewrites select requests to the site root, allowing your client-side 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.
You can also specify regular expressions to specifically allow or disallow additional paths from being affected.
This functionality is commonly needed by single page web-apps.
Install package
npm install connect-pushstate --save
Load the middleware by adding the following line of JavaScript.
var pushState = require('connect-pushstate');
Add the pushState
middleware call to your server definition, amongst your other middleware.
The pushState method accepts an options object as an optional parameter with the following properties.
pushState({ root: '/foo' })
pushState({ allow: '^/api' })
You might need this option if your client app and API are on the same server.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.
For a quick demo, see the examples directory, or run the test suite.
cd examples
node server.js
Execute the test suite
npm test
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.
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 8,494 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.