
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
browserver-router
Advanced tools
A platform-agnostic router for HTTP listeners that follow the node.js spec
This is a simple and unambitious router implementation that can be used in either the browser or any CommonJS environment. It was designed for browserver, but will work with any server that conforms to the node.js http.Server
API.
var Router = require("router")
var router = Router({
"/salutation/:name": {
GET: function(req, res) {
res.writeHead(200)
res.end("Hello, " + req.params[0] + ".")
},
DELETE: function(req, res) {
res.writeHead(200)
res.end("Goodbye, " + req.params[0] + ".")
},
"*": function(req) {
throw new Error("No such salutation")
}
},
"/method": function(req, res) {
res.writeHead(200)
res.end("Matched method: " + req.method)
}
})
var http = require("http")
var server = http.createServer(router)
server.listen(8000)
var router = Router({
"/salutation/:name": {
GET: function(req, res) {
res.writeHead(200)
res.end("Hello, " + req.params[0] + ".")
},
DELETE: function(req, res) {
res.writeHead(200)
res.end("Goodbye, " + req.params[0] + ".")
},
"*": function(req) {
throw new Error("No such salutation")
}
},
"/method": function(req, res) {
res.writeHead(200)
res.end("Matched method: " + req.method)
}
})
var server = http.createServer(router)
var ws = new eio.Socket({host: "myserver.com"})
server.listen(ws)
Creates a new router, which is a function with the standard (req, res)
signature. If a routes
object is passed, it will .route(key, value)
will be called for each key.
var router = Router({
"/": {
GET: function(req, res) {
res.writeHead(200)
res.end("OK")
}
}
})
Adds a route to match. Both arguments are required.
router.route("/salutation/:name", {
GET: function(req, res) {
res.writeHead(200)
res.end("Hello, " + req.params[0] + ".")
},
DELETE: function(req, res) {
res.writeHead(200)
res.end("Goodbye, " + req.params[0] + ".")
}
})
The route
string is compiled into a regular expression, using the same logic as the Backbone.js router, in which :param
strings match a single url component between slashes and *
splats match any number of url components. Any matching parameters are used to populate the req.params
array by match position.
The methodMap
object maps method names (such as GET
and POST
) to handlers.
A fallback handler that matches all routes can be specified using *
as the method name.
Handlers can either use the standard function(req, res){}
signature, or a function(req){}
signature with the response omitted, in which the response is automatically generated like this:
router.route("/random-error", function(req) {
var ok = Math.random() > .5
if (!ok) {
// equivalent to
// res.writeHead(500, {"Content-Type": "text/plain"})
// res.end("An error occurred")
throw new Error("An error occurred")
}
else {
// equivalent to
// res.writeHead(204)
// res.end()
return
}
})
A convenient shortcut for router.route(route, {"*": handler})
, to fire on any otherwise unhandled method.
FAQs
A platform-agnostic router for HTTP listeners that follow the node.js spec
The npm package browserver-router receives a total of 7 weekly downloads. As such, browserver-router popularity was classified as not popular.
We found that browserver-router 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.