-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
256 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 UberProxy | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var NPM = require('npm'); | ||
var Fs = require('fs'); | ||
|
||
exports.setup = function(parser) { | ||
}; | ||
|
||
var packages = []; | ||
function checkPackage(pkg) { | ||
if (pkg['uberproxy-plugin']) { | ||
packages.push([pkg.name.replace(/^uberproxy-?/i, ''), pkg.realPath]); | ||
} | ||
}; | ||
|
||
exports.main = function(argv) { | ||
NPM.load(function() { | ||
NPM.commands.list([], true, function(err, npm) { | ||
NPM.config.set("global", true); | ||
for (var i in npm.dependencies) { | ||
if (npm.dependencies.hasOwnProperty(i)) { | ||
checkPackage(npm.dependencies[i]); | ||
} | ||
} | ||
NPM.commands.list([], true, function(err, npm) { | ||
for (var i in npm.dependencies) { | ||
if (npm.dependencies.hasOwnProperty(i)) { | ||
checkPackage(npm.dependencies[i]); | ||
} | ||
} | ||
Fs.writeFileSync(__dirname + "/../plugins/npm.js", "exports.plugin = " + JSON.stringify(packages)); | ||
console.log("Updated npm.js"); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# UberProxy | ||
|
||
UberProxy is a **reverse proxy** written in NodeJS. It was designed to be fast and easy to configure. | ||
|
||
## Features | ||
|
||
1. Highly configurable | ||
- Provides a [RESTful interface](usage/#restful-interface) to add and remove workers, SSL domains, etc. | ||
2. Easy to extend. | ||
- [Write plugins](plugins) in Javascript! | ||
- Everything is a plugin internally | ||
- [Redirect](plugins/redirect.js) | ||
- [Logging](plugins/logs.js) | ||
3. Fast (NodeJS is neat handling lots of I/O) | ||
4. Efficient uploads | ||
- The proxy buffer to disk a file upload | ||
- When it's ready it forwards to the worker | ||
- The Proxy deal much better with slow connections | ||
5. Throttle connections to workers (by default 20 per worker) | ||
6. SSL support | ||
7. URL sanitization | ||
- `//foobar///` will be rewrite to `/foobar` before forwarding the app | ||
8. The workers are in control of everything: | ||
- Rewrite hostname | ||
- Rewrite URL | ||
- Expose URL (with regular expressions) they can work | ||
- If a worker can serve `^/(foo|bar)/.+`, any other request will generate a `404 Error page` in the proxy itself. | ||
- They can choose which plugins to use (Global plugins may apply any ways) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Setup | ||
|
||
## Instalation | ||
|
||
UberProxy can be installed easily with npm. | ||
|
||
```bash | ||
npm install -g uberproxy | ||
``` | ||
|
||
If you wish to have the latest code you can install it from github as well: | ||
|
||
```bash | ||
git clone https://github.com/uberproxy/uberproxy.git | ||
cd uberproxy | ||
npm install | ||
ln -s `pwd`/index.js /usr/local/bin/uberproxy | ||
``` | ||
|
||
## Configuration | ||
|
||
UberProxy needs a **configuration file**. To make things simple `uberproxy setup` will create a configuration file in the current directory. | ||
|
||
```bash | ||
uberproxy setup | ||
# or | ||
ubeproxy setup -c configuration.json | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Usage | ||
|
||
## Run | ||
|
||
```bash | ||
uberproxy server | ||
``` | ||
|
||
It will run a bare proxy, most requests will return a `Not Found` error. We must add workers for it to work. | ||
|
||
## RESTful interface | ||
|
||
The protocol is pretty simple, it can be impemented in any language which has a `http` client library. | ||
|
||
``` | ||
POST /_uberproxy/register HTTP/1.1 | ||
Host: foobar.com | ||
X-Auth: sha256($secret + "\0" + "register" + "\0" + "{json_data}") | ||
{json_data} | ||
``` | ||
|
||
The `X-Auth` is a `sha256` hash which ensures the URI and `json_data` are legit. The `$secret` value is defined in the configuration file (usually `config.yml`). | ||
|
||
### PHP Client | ||
Our [PHP](https://github.com/uberproxy/php-sdk) client implements the restful interface and provides a set of really simple classes to configurate UberProxy on demand. Think of it as a `Makefile` for deploying your application, once your application is ready, you execute a PHP file which describes your application to the proxy. | ||
|
||
#### Installation | ||
|
||
```bash | ||
composer require uberproxy/php-client | ||
``` | ||
|
||
#### Usage | ||
|
||
```php | ||
$client = new UberProxy\Client("my.proxy.com", $secret); | ||
|
||
$client->register() | ||
->worker($my_ip_address) | ||
->addHost('myrealappdomain.com') | ||
->enablePlugin('redirect') | ||
->extra([ | ||
'redirectTo' => ['http://www.myrealappdomain.com', 301], | ||
])->send(); | ||
|
||
$client->register() | ||
->worker($my_ip_address) | ||
->addHost('www.myrealappdomain.com') | ||
->addRoute("/") | ||
->addRoute("/about") | ||
->addRegexRoute('/(foo|bar)/.+') | ||
->rewriteRoute("/(foo|bar)/(.+)", "index.php?action=$1&extra=$2") | ||
->send(); | ||
``` | ||
|
||
The first register is listening for requests for `myrealappdomain.com` and enables the plugin `redirect`. In the extra section it gives the data the plugin needs (in this case, redirect to `www.myrealappdomain.com` with a 301 code). | ||
|
||
The second register is registering an application for `www.myrealappdomain.com` with the following descriptions: | ||
|
||
1. Forward only routes `/`, `/about` and `/(foo|bar)/.+`. Any other request would return a `404` error page in the proxy itself. | ||
2. Rewrite `/foo/something/extra?q=1` to `index.php?q=1&action=foo&extra=something/extra` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.