Permalink
Browse files

http-proxy sample added!

  • Loading branch information...
1 parent 82e71e6 commit 6f5171205c8adf9064af514b8ef28da3dede2ff1 @gevorg gevorg committed Nov 29, 2011
Showing with 74 additions and 0 deletions.
  1. +29 −0 README.md
  2. +45 −0 examples/example_proxy.js
View
@@ -70,6 +70,35 @@ app.get('/', basic.apply, function(req, res) {
res.send("Welcome to private area!");
});
```
+## Example with [http-proxy](https://github.com/nodejitsu/node-http-proxy/) integration
+```javascript
+/**
+ * Requesting new authentication instance.
+ */
+var basic = auth({
+ authRealm : "Private area.",
+ authList : ['mia:supergirl', 'Carlos:test456', 'Sam:oho']
+});
+
+/**
+ * Create a proxy server with custom application logic.
+ */
+httpProxy.createServer(function(req, res, proxy) {
+ basic.apply(req, res, function() {
+ proxy.proxyRequest(req, res, {
+ host : 'localhost',
+ port : 9000
+ });
+ });
+}).listen(8000);
+
+/**
+ * Destination server.
+ */
+http.createServer(function(req, res) {
+ res.end('request successfully proxied!');
+}).listen(9000);
+```
## Configurations
- `authRealm` - Authentication realm.
@@ -0,0 +1,45 @@
+/**
+ * HTTP authentication module.
+ */
+var auth = require('../lib/http-auth');
+
+/**
+ * HTTP module.
+ */
+var http = require('http');
+
+/**
+ * HTTP proxy module.
+ */
+var httpProxy = require('http-proxy');
+
+
+/**
+ * Requesting new authentication instance.
+ */
+var basic = auth({
+ authRealm : "Private area.",
+ authList : ['mia:supergirl', 'Carlos:test456', 'Sam:oho']
+});
+
+/**
+ * Create a proxy server with custom application logic.
+ */
+httpProxy.createServer(function(req, res, proxy) {
+ basic.apply(req, res, function() {
+ proxy.proxyRequest(req, res, {
+ host : 'localhost',
+ port : 9000
+ });
+ });
+}).listen(8000);
+
+/**
+ * Destination server.
+ */
+http.createServer(function(req, res) {
+ res.end('request successfully proxied!');
+}).listen(9000);
+
+// Log url.
+console.log("Server running at http://127.0.0.1:8000/");

0 comments on commit 6f51712

Please sign in to comment.