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.
backbone.subroute
Advanced tools
Backbone.subroute extends the functionality of Backbone.router such that each of an application's modules can define its own module-specific routes.
#Backbone Subroute
##About
Backbone's Router feature is really powerful, but for large multi-module apps, it can quickly become large and unmaintainable.
Backbone.SubRoute extends the functionality of Backbone.Router such that each of an application's modules can define its own module-specific routes. This eliminates the need for one monolithic Router configuration, The base router can instead act as a simple delegator that forwards module-specific routes to the appropriate module-specific SubRoute.
For example, given this URL: http:example.org/myModule/foo/bar
...the base router would be responsible for invoking and delegating to the proper module based on "myModule". The module would then have its own SubRoute which would have its own mappings for the foo/bar part.
This project is based on a Gist by Tim Branyen, and used with permission from the original author.
Subroute is lightweight, weighing in at under 300 bytes minified and gzipped.
Latest Stable Release: 0.4.5
Unreleased Edge Version (master)
Visit the project repo to download the latest unreleased code (may be unstable).
Join the Backbone.Subroute Google Group to discuss new features and stay-up-to-date on project updates.
Has Subroute been helpful to you? If you'd like to give back, here are a few ways:
Pull requests are welcome. For any significant change or new feature, please start a discussion in the Google Group, or log an issue first. This will save you some time, in case your idea is deemed not general enough to be included in the project.
Before submitting a pull request, please:
specs/
directory. See the Testing section for more info.http://localhost:<port>/spec/
Subroute uses Grunt to verify each build. If you are not familiar with Grunt, check out the getting started guide for an introduction and installation instructions.
Before submitting a pull request, please run the grunt task. To do so:
First, install local development dependencies. From the root Subroute directory, run:
npm install
then
grunt
Grunt will perform these tasks:
To reduce merging and styling issues related to whitespace and formatting, the jsbeautifier task normalizes all formatting in project source. If you fail to run grunt
prior to check-in, and any files have not been beautified, Travis-CI will reject the checkin.
The code will be minified and saved to dist/backbone.subroute.min.js
.
Javascript files are checked for errors using JSHint. The JSLint configuration is driven by the .jshintrc
file.
Test specs are run headlessly using PhantomJS
Code coverage is enforced using Istanbul. Currently not every feature of Subroute has coverage.
But the enforced coverage levels are set such that code coverage cannot decrease. Over time, more tests will be added to increase coverage
to as close to 100% as possible (help with this is greatly appreciated!)
The Grunt build is run automatically using Travis-CI upon every pull request and push to master. But if any errors are found, you'll need to fix them and re-submit your pull request. So please run the grunt task locally to save time.
Let's say that you've got a section of your web app multiple pieces of functionality all live under the URL prefix http://yourserver.org/books
. Here's how you'd create your subrouter.
var BooksRouter = Backbone.SubRoute.extend({
routes: {
"" : "showBookstoreHomepage",
"search" : "searchBooks",
"view/:bookId" : "viewBookDetail",
},
showBookstoreHomepage: function() {
// ...module-specific code
},
searchBooks: function() {
// ...module-specific code
},
viewBookDetail: function(bookId) {
// ...module-specific code using bookId param
}
});
Note that the subrouter, itself, doesn't know or care what its prefix is. The prefix is only provided when instantiating specific instances of the sub-router. This makes sub-routers especially useful for reusing common pieces of code.
To use your sub-router, simply call its constructor and provide a prefix, like so:
var mySubRouteInstance = new BooksRouter("books");
Given the example above, with an instance of the sub-route being created with the "books"
argument passed as a constructor, and deployed on a server with a base URL of yourserver.org
, this results in the following routes being created:
Subroute | Expands To | Matches URL |
---|---|---|
"" | books | http://yourserver.org/books |
"search" | books/search | http://yourserver.org/books/search |
"view/:bookId" | books/view/:bookId | http://yourserver.org/books/view/1234 |
When instantiating a SubRouter, you may wish to provide some parameters from the calling code, which may be needed in your sub-router code. The sub-router constructor takes an optional object literal as a second argument.
For instance:
var mySubRouteInstance = new BooksRouter("books", {locale: "en_US", isVIP: true));
Then in your sub-router definition, you can access these parameters using the familiar Backbone options
object, used in other Backbone components. Like so:
initialize: function(options) {
this.locale = options.locale;
this.isVIP = options.isVIP;
}
Thanks to @carpeliam for this feature.
Backbone treats routes with trailing slashes as totally different routes than those without. For instance, these are two different routes in Backbone:
"search"
"search/"
URL semantics aside, many people have found this behavior annoying. If you're one of them, and you want to support either format without duplicating each and every one of your routes, you can pass the optional createTrailingSlashRoutes
parameter when you instantiate your sub-router.
For example:
var mySubRouteInstance = new BooksRouter("books", {createTrailingSlashRoutes: true});
Using the examples above, a URL of either http://yourserver.org/books/search
or http://yourserver.org/books/search/
would fire the searchBooks()
callback.
The spec
directory in the repo contains a suite of test specs. To run them, start a web server in the project directory, then point your browser to the spec
directory.
The test specs can also be run online here.
Released 29 April 2015
Released 13 October 2014
Released 1 September 2014
Released 9 May 2014
Released 7 April 2014
Released 23 September 2013
routes
hash. Big thanks to @mikesnare for suggesting the fix, and @joshuaballoch for providing the specs to identify the issue.Released 17 July 2013
Released 22 January 2013
Released 26 October 2012
Released 30 August 2012
navigate
method where separator /
character was omitted after prefixReleased 15 July 2012
createTrailingSlashRoutes
propertyReleased 16 April 2012
##License The MIT License (MIT)
Copyright (c) 2012 Model N, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Backbone.subroute extends the functionality of Backbone.router such that each of an application's modules can define its own module-specific routes.
The npm package backbone.subroute receives a total of 2,147 weekly downloads. As such, backbone.subroute popularity was classified as popular.
We found that backbone.subroute 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.