Permalink
Browse files

Adapt the proxy so that it can be mounted as middleware

  • Loading branch information...
1 parent df3ce96 commit 84411e1f2b14bfd22d20d80d37843caf5ff4c19b @evdb evdb committed Jun 14, 2012
Showing with 19 additions and 5 deletions.
  1. +12 −0 README.md
  2. +4 −2 examples/app.js
  3. +3 −3 lib/image-proxy.js
View
@@ -14,6 +14,18 @@ It provides:
npm install connect-image-proxy
+and then in your code (eg an Express app):
+
+ var image_proxy = require('connect-image-proxy');
+
+ app.configure(function(){
+ ....
+
+ // mount the proxy at '/proxy'
+ app.use( '/proxy', image_proxy() );
+ ....
+ });
+
## Usage
View
@@ -11,13 +11,15 @@ app.configure(function(){
app.use(express.logger('dev'));
app.use(express.favicon());
app.use("/images", express.static(__dirname + '/public'));
+
+ // Use the proxy
+ app.use('/proxy', image_proxy() );
+
app.use(app.router);
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
-app.get('/proxy', image_proxy.run);
-
app.get('/', function(req, res){
res.render('index.jade');
});
View
@@ -6,7 +6,8 @@ http = require('http'),
gm = require('gm'),
temp = require('temp');
-var run = function(req, res){
+module.exports = function () {
+ return function image_proxy (req, res){
var remoteUrl = decodeURI(req.param('url'));
var urlObject = url.parse(remoteUrl);
@@ -88,6 +89,7 @@ var run = function(req, res){
});
}
+ };
};
function validateMime(name)
@@ -100,5 +102,3 @@ function validateMime(name)
else
return true;
}
-
-exports.run = run;

0 comments on commit 84411e1

Please sign in to comment.