Giter Club home page Giter Club logo

esteves's Introduction

esteves - add, remove or inject content for a given webpage

Afterwards I lean back in the chair
And keep smoking.
As long as Destiny allows, I will keep smoking.
(If I married my washwoman's daughter
I might conceivably be happy.)
Given this, I rise and go to the window.
The man has come out of the Tobacco Shop (putting change into his pocket?).
Ah, I know him: he is Esteves without methaphysics.
(The Tobacco Shop owner has come to the door.)
As if by a divine instinct, Esteves turned around and saw me.
He waved hello, I shouted back "Hello there, Esteves!" and the universe
Reconstructed itself to me, without ideals or hope, and the owner of the Tobacco Shop smiled.

Tobacco Shop by Fernando Pessoa

Esteves is a small lib that allows for easy html rewriting as well as serving new resources. It builds upon node-http-proxy and trumpet.

The feature set is quite basic, but the src is very easy to read. Fork and change at will.

All my node projects will have a completely unrelated name, and I will further accompany the readme with a poem.

Is it any good?

Yes

Similar Projects

TODO

  • Support external config
  • Support regexes in uri definition
  • Support HTTPS

Example


var http      = require('http'),
    httpProxy = require('http-proxy'),
    fs        = require('fs'),
    intercept = require('../')

// so that node doesn't hang on conn refused
process.on('uncaughtException', function(err) {
  console.log('uncaughtException: ', err);
});


var imgHeaders = {'Content-Type': 'image/gif', 'Pragma-directive': 'no-cache','Cache-directive': 'no-cache','Cache-control': 'no-cache','Pragma': 'no-cache','Expires': '0'};

var proxy = new httpProxy.createProxyServer();

//accept-encoding must be false, currently content-encoding is not supported (gzip)
var mware = new intercept.createMiddleware(proxy, {userAgent: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36',
												   acceptEncoding: false});

mware.afterSelection('http://my.site.pt/', 'head', function(cb){
	cb(null, '\n\t<script src="/myCustomScript.js"></script>\n');
});

mware.replaceSelection('http://my.site.pt/', 'h1#logo', function(cb){
	cb(null, '<img id="ad_logo" src="/random_img.gif" onload="this.src=\'/asset/ad/logo.svg\';">');
});

mware.whenUri('http://my.site.pt/myCustomScript.js', function(cb){
	cb(null, {code: 200, headers: imgHeaders, response: fs.readFileSync('examples/wwwroot/myCustomScript.js')});
});

mware.whenUri('http://my.site.pt/random_img.gif', function(cb){
	cb(null, {code: 200, headers: imgHeaders, response: fs.readFileSync('examples/wwwroot/1x1.gif')});
});

License

MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.