Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Pluggable and hackable reverse HTTP proxy gateway for traffic forward and replay
Pluggable, hackable and middleware-oriented HTTP/s proxy gateway for traffic forward, map and replay, built for node.js.
rocky
essentially acts as a fully configurable reverse HTTP proxy router forwarding and/or replaying the traffic to one or multiple backends, allowing you to perform multiple actions during that process.
It can be used programmatically or via its command-line interface.
Still beta
Migrating systems if not a trivial thing, and it's even more complex if we're talking about production systems with requires high availability. Taking care about consistency and public interface contract should be a premise in most cases.
That's the main reason why rocky
borns: it was mainly designed to become a crucial tool to assist during a backend migration strategy. You could use it as a frontend proxy server or integrated in your existent node.js
backend.
rocky
will take care about HTTP routing discerning the traffic and forwarding/replaying it accordingly to your desired new backend.
You can use it as well for testing/maintance proposals, for instance replaying your traffic from one enviroment to another ones.
|==============|
| The Internet |
|==============|
||||
|==============|
| HTTP proxy |
|--------------|
| Rocky |
|~~~~~~~~~~~~~~|
| HTTP Router |
|==============|
|| |
(duplex) // \ (one-way)
// \
// \
/----------\ /----------\ /----------\
| target | | replay 1 | -> | replay 2 | (*N)
\----------/ \----------/ \----------/
npm install rocky --save
For command-line interface usage, install it as global package:
npm install -g rocky
Start rocky HTTP proxy server
Usage: rocky [options]
Options:
--help, -h Show help [boolean]
--config, -c File path to TOML config file [required]
--port, -p rocky HTTP server port
--forward, -f Default forward server URL
--replay, -r Define a replay server URL
--key, -k Path to SSL key file
--cert, -e Path to SSL certificate file
--secure, -s Enable SSL certification validation
--debug, -d Enable debug mode [boolean]
-v, --version Show version number [boolean]
Examples:
rocky -c rocky.toml \
-f http://127.0.0.1:9000 \
-r http://127.0.0.1
rocky --config rocky.toml --port 8080 --debug
Supported params
string
- Default forward URLarray<string>
- Optional replay server URLsboolean
- Enable debug mode. Default false
boolen
- Enable SSL certificate validation. Default to false
number
- TCP port to listen. Default to 3000
boolean
- Enable/disable x-forward headersstring
- Passes the absolute URL as the path (useful for proxying to proxies)boolean
- Always forward the target hostname as Host
headerboolen
rewrites the location hostname on (301/302/307/308) redirectsstring
- Path to SSL certificate filestring
- Path to SSL key filestring
- HTTP method for the route. Default to all
string
- Default forward URLarray<string>
- Optional replay server URLsThe configuration file must be in TOML format
port = 8080
forward = "http://google.com"
replay = ["http://duckduckgo.com"]
[ssl]
cert = "server.crt"
key = "server.key"
[/users/:id]
method = "all"
forward = "http://new.server"
[/oauth]
method = "all"
forward = "http://auth.server"
[/*]
method = "GET"
forward = "http://old.server"
Example using Express
var rocky = require('rocky')
var express = require('express')
var proxy = rocky()
// Default proxy config
proxy
.forward('http://new.server')
.replay('http://old.server')
.replay('http://log.server')
.options({ forwardHost: true })
// Configure the routes to forward/replay
proxy
.get('/users/:id')
// Set up the express server
var app = express()
// Plug in the rocky middleware
app.use(proxy.middleware())
// Old route (won't be called since it will be intercepted by rocky)
app.get('/users/:id', function () { /* ... */ })
Example using the built-in HTTP server
var rocky = require('rocky')
var proxy = rocky()
// Default proxy config
proxy
.forward('http://new.server')
.replay('http://old.server')
.options({ forwardHost: true })
// Configure the routes to forward/replay
proxy
.get('/users/:id')
proxy
.get('/search')
proxy.listen(3000)
For more usage case, take a look to the examples
Creates a new rocky instance with the given options.
You can pass any of the allowed params at configuration level, or take a look to the http-proxy supported options
Alias: target
Define a default target URL to forward the request
Add a server URL to replay the incoming request
Define/overwrite rocky server options
Use the given middleware function for all http methods on the given path, defaulting to the root path.
Subscribe to a proxy event. See support events here
Return: Function(req, res, next)
Return a connect/express compatible middleware
Raw HTTP request/response handler.
Starts a HTTP proxy server in the given port
Close the HTTP proxy server, if exists.
A shortcut to rocky.server.close(cb)
Return: Route
Add a route handler for the given path for all HTTP methods
Return: Route
Return: Route
Return: Route
Return: Route
Return: Route
Return: Route
http-proxy instance
HTTP router instance
HTTP/HTTPS server instance.
Only present if listen()
was called starting the built-in server.
Alias: target
Overwrite forward server for the current route.
Overwrite replay servers for the current route.
Overwrite default proxy options for the current route.
Subscribes to a specific event for the given route. Useful to incercept the status or modify the options on-the-fly
Supported events:
opts, req, res
- Fired when the request forward process startsopts, req, res
- Fired when a request is replayed to another backenderr, req, res
- Fired when the forwarded request failserr, req, res
- Fired when the replayed request failsCreate a standalone rocky
server with the given config
options.
See the supported config fields
var config = {
'forward': 'http://google.com',
'/search': {
method: 'GET',
forward: 'http://duckduckgo.com'
replay: ['http://bing.com', 'http://yahoo.com']
},
'/users/:id': {
method: 'all'
},
'/*': {
method: 'all',
forward: 'http://bing.com'
}
}
rocky.create(config)
Accessor for the http-proxy API
Current rocky package semver
MIT - Tomas Aparicio
FAQs
Full-featured, middleware-oriented, hackable HTTP and WebSocket proxy
The npm package rocky receives a total of 1,785 weekly downloads. As such, rocky popularity was classified as popular.
We found that rocky 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.