Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adapt the proxy so that it can be mounted as middleware

  • Loading branch information...
commit 84411e1f2b14bfd22d20d80d37843caf5ff4c19b 1 parent df3ce96
Edmund von der Burg evdb authored

Showing 3 changed files with 19 additions and 5 deletions. Show diff stats Hide diff stats

  1. +12 0 README.md
  2. +4 2 examples/app.js
  3. +3 3 lib/image-proxy.js
12 README.md
Source Rendered
@@ -14,6 +14,18 @@ It provides:
14 14
15 15 npm install connect-image-proxy
16 16
  17 +and then in your code (eg an Express app):
  18 +
  19 + var image_proxy = require('connect-image-proxy');
  20 +
  21 + app.configure(function(){
  22 + ....
  23 +
  24 + // mount the proxy at '/proxy'
  25 + app.use( '/proxy', image_proxy() );
  26 + ....
  27 + });
  28 +
17 29
18 30 ## Usage
19 31
6 examples/app.js
@@ -11,13 +11,15 @@ app.configure(function(){
11 11 app.use(express.logger('dev'));
12 12 app.use(express.favicon());
13 13 app.use("/images", express.static(__dirname + '/public'));
  14 +
  15 + // Use the proxy
  16 + app.use('/proxy', image_proxy() );
  17 +
14 18 app.use(app.router);
15 19 app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
16 20 });
17 21
18 22
19   -app.get('/proxy', image_proxy.run);
20   -
21 23 app.get('/', function(req, res){
22 24 res.render('index.jade');
23 25 });
6 lib/image-proxy.js
@@ -6,7 +6,8 @@ http = require('http'),
6 6 gm = require('gm'),
7 7 temp = require('temp');
8 8
9   -var run = function(req, res){
  9 +module.exports = function () {
  10 + return function image_proxy (req, res){
10 11
11 12 var remoteUrl = decodeURI(req.param('url'));
12 13 var urlObject = url.parse(remoteUrl);
@@ -88,6 +89,7 @@ var run = function(req, res){
88 89 });
89 90 }
90 91
  92 + };
91 93 };
92 94
93 95 function validateMime(name)
@@ -100,5 +102,3 @@ function validateMime(name)
100 102 else
101 103 return true;
102 104 }
103   -
104   -exports.run = run;

0 comments on commit 84411e1

Please sign in to comment.
Something went wrong with that request. Please try again.