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.
routington
Advanced tools
Routington is a trie-based URL router. Its goal is only to define and match URLs. It does not handle methods, headers, controllers, views, etc., in anyway. It is faster than traditional, linear, regular expression-matching routers, although insignficantly, and scales with the number of routes.
The purpose of this router isn't for performance, but to bring more structure to URL routing. The intention is for you to build a framework on top either in node.js or in the browser.
For a node.js implementation, we have built dispatchington. This can be used either as a standalone or as a replacement for Express' router.
var routington = require('routington')
var router = routington()
router
is the root Node
in the trie. All node
s will have router
as furthest ancestor.
Every node on a tree is an instance of Node
. You only construct the root. A node
has the following properties:
child {}Node
- String based child definitions.
For example, node.child['post']
will return a child node with node.string === 'post'
children []Node
- Name/regex based child definitionsparent Node
- The parent of the nodename
- Name of the node (for parameter matching)string
- String to match the URL fragmentregex
- Regular expression to match the URL fragmentvar nodes = routington.define('/:identity(page|petition)/:id([0-9a-f]{24})')
route
is a definition of a route and is an extension of Express' routing syntax.
route
, however, can only be a string.nodes
is an array of node
s.Each fragment of the route, delimited by a /
, can have the following signature:
string
- ex /post
string|string
- |
separated strings, ex /post|page
:name
- Wildcard route matched to a name(regex)
- A regular expression match without saving the parameter (not recommended):name(regex)
- Named regular expression matchEach node
of nodes
will always have node.string === ''
.
URLs are always treated with a trailing /
by design.
You should always name your regular expressions otherwise you can't use the captured value.
The regular expression is built using new RegExp('^(' + regex + ')$', 'i')
,
so you need to escape your string, ie \\w
.
You can always pre-define names or regular expressions before. For example, I can define:
router.define('/page/:id(\\w{3,30})')
// later, :id will have the same regexp
// so you don't have to repeat yourself
router.define('/page/:id/things')
router.define('/page/:id(\\w{3,30})')
var match = router.match('/page/taylorswift')
match
, unless null
, will be an object with the following properties:
param
- A list of named parameters, ex, match.param.id === 'taylorswift'
.node
- The matched node.
Will always have name.string === ''
.IE9+
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong me@jongleberry.com
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
Trie-based URL Routing
The npm package routington receives a total of 368 weekly downloads. As such, routington popularity was classified as not popular.
We found that routington demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.