h2non / rocky Goto Github PK
View Code? Open in Web Editor NEWFull-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js (deprecated)
License: MIT License
Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js (deprecated)
License: MIT License
rocky
.get('/users/:id')
.toPath('/profile/:id')
.headers({
'X-API-Version': '1.0'
})
.forward('http://new.server')
To incercept both request and response
Sometimes we don't wanna forward the request
proxy
.get('/users/admin')
.reply(401, { 'Content-Type': 'application/json' }, { message: 'Forbidden' })
proxy.get('/test')
.use(function (req, res, next) {
// req.rocky.options => { target: 'http://server' ... }
})
Proposed at #28
Buffer all the body payload, then parse it properly, and finally expose it to the forward/replay middleware
rocky
.get('/test')
.options({
disableHost: true
})
Support both regexp and filter function
route.transformBodyRequest(transformer, { filter: /application/json/ })
route.transformBodyRequest(transformer, { filter: function () { ... } })
Would be awesome to make rocky installable via PM2,
I recently embedded a npm install procedure + start with PM2 to make possible to install software easily by doing something like that:
$ pm2 install <npm-package-name>
There is a small documentation about the system
Tell me if you are interested to build a module like that, I can make modifications on the PM2 configuration system and related.
Add test coverage!
Like with responses!
Probably a good fit could be:
route.useReplay(middleware)
proxy.get('/test').bufferBody()
proxy
.post('/signup')
.transformRequestBody(function () { ... })
.replay(['http://old.server'], { originalBody: true })
This will make rocky
more lightweight. Proposed name: rocky-cli
Split routing layer by host
header
Currently that could be achieved using a middleware
Based on request headers and payload data (requires buffering it)
Better API docs, usage example and explanation (injected fields in request, inversion of control...)
rocky()
.matchHeader('X-Version', '1.0')
.forward('http://server.net')
.get('/users/:id')
rocky()
.balancer(['http://1.server.net', 'http://2.server.net'])
proxy.useParam(middleware)
In some scenarios, once the stream has been consumed and therefore the buffer is empty, it's not possible to replay the request with the proper payload.
A nice-to-have feature. Could be useful to discern the proxy behavior according to some specific request headers/params.
The API may look like this:
proxy.get('/users/:id')
.match('X-Version', /^1.*/)
.forward('http://old.server')
.match('X-Version', /^2.*/)
.forward('http://new.server')
Alternative implementation, using internally the router
middleware
proxy.get('/users/:id', { 'X-Version', /^1.*/ }, function () { ... })
.forward('http://google.es')
Internally it should be implemented via middleware
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.