Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
hyperprox
Advanced tools
Readme
simple HTTP proxy based on hyperquest
$ npm install hyperprox
Create a proxy by passing a function that will resolve what backend to use to the given request
var http = require("http")
var hyperprox = require('hyperprox')
var backends = hyperprox(function(req){
// calculate the proxy destination
var port = req.url=='/a' ? 8081 : 8082
return 'http://127.0.0.1:' + port
})
// the front facing web server
var router = http.createServer(backends.handler())
backends.on('request', function(req, res){
})
backends.on('route', function(req, address){
})
var serverA = http.createServer(function(req, res){
res.end('serverA')
})
var serverB = http.createServer(function(req, res){
res.end('serverB')
})
router.listen(8080)
serverA.listen(8081)
serverB.listen(8082)
We can generate a duplex stream for a request that will auto-route - this lets us filter the input and output:
var through = require('through2')
var backends = hyperprox(function(req){
var port = req.url=='/a' ? 8081 : 8082
return 'http://127.0.0.1:' + port
})
var router = http.createServer(function(req, res){
var proxy = backends.duplex(req, res)
// filter the request body
var inputFilter = through(function(chunk, enc, next){
this.push(chunk.toString() + 'a')
next()
})
// filter the response body
var outputFilter = through(function(chunk, enc, next){
this.push(chunk.toUpperCase())
next()
})
// REQUEST -> INPUT FILTER -> PROXY -> OUTPUT FILTER -> RESPONSE
req.pipe(inputFilter).pipe(proxy).pipe(outputFilter).pipe(res)
})
Your routing function can be asynchronous - this means you can ask an external service for routing data:
If you define next
in the parameters then it will be treated as an async router.
var proxy = hyperprox(function(req, next){
loadRoute(req.url, function(err, address){
next(err, address)
})
})
hyperprox.proxy(req, res, address, [input, output])
A direct proxy function that will send req via address to res
Input and output are optional override streams to replace req and res
var backends = hyperprox(function(req, next){})
Create a new proxy by passing a function that will resolve the backend address and pass it to the 'next' function
backends.handler()
Return a function(req,res){}
that will proxy requests using the routing function
backends.proxy(req, res, address, [input, output])
A direct proxy that will pipe req via address and to res
If input and output are provided - they will be used as the streams rather than req and res
backends.resolve(req, done)
The resolving function that goes via the user supplied function
backends.duplex(req, res)
Return a duplex stream going through the backend - you can write it to the original request / response how you want:
var duplex = backends.duplex(req, res)
req.pipe(duplex).pipe(res)
If there is an error with routing the response will be set to 500 and the backend skipped
backends.on('request', function(req, res){})
when a request arrives at the proxy
backends.on('route', function(req, address){})
Once a routing decision has been made
MIT
FAQs
simple HTTP proxy based on hyperquest
The npm package hyperprox receives a total of 1,015 weekly downloads. As such, hyperprox popularity was classified as popular.
We found that hyperprox 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.