connect-tweek

A extensible proxy middleware for Connect/Express.

npm install connect-tweek
4 downloads in the last week
4 downloads in the last month

connect-tweek

A extensible proxy middleware for Connect/Express. Concept taken from Newstweek.

Usage

var connect = require('connect')
  , proxy = require('connect-tweek');

proxy
  .use(function(res, body, next) {
    // display body
    console.log(body);
    next();
  })
  .use(function(res, body, next) {
    // add access control headers
    res.headers['Access-Control-Allow-Origin'] = '*/*';
    res.headers['Access-Control-Allow-Credentials'] = 'true';
    next();
  })
  .use(function(res, body, next) {
    // modify response body
    res.body = body.replace('foo', 'bar');
    next();
  })
  .use('www.youtube.com', function(res, body, next) {
    // scrape for YouTube contents.
    var cheerio = require('cheerio')
      , $ = cheerio.load(body);

    $('body')
      .prepend('<img src="http://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg">'); // inject lenna.

    res.body = $.html();
    next();
  });

// http://www.google.com.proxy.example.com/humans.txt
//   -> http://www.google.com/humans.txt
var app = connect()
  .use(connect.vhost('*.proxy.example.com', proxy({ suffix: 'proxy.example.com' })))
  .listen(3000);

License

(The MIT License)

Copyright (c) 2012 Uniba Inc. <info@uniba.jp>

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.

npm loves you