+
Skip to content

gisenberg/transformer-proxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

transformer-proxy build status

A middleware component for node-http-proxy to transform the response from the proxied server. It can be used to transform JavaScript, pictures or any other data. If you're looking for an easy solution to modify HTML, have a look at harmon which uses trumpet for modifying HTML.

Installation

$ npm install transformer-proxy

Basic example

A basic example can be found in examples/simple.js. The quintessence is that you can tell your connect-app to use an own function for transforming all data.

var transformerFunction = function (data, req) {
  // do something with the data and return it
  return data + "\n // an additional line the end of every file";
}
app.use(transformerProxy(transformerFunction));

The example also includes additional code for setting up a basic server and the corresponding proxy.

Start it as follows:

$ cd node_modules/transformer-proxy/examples
$ node simple.js

When visiting localhost:3000 you should see:

A simple HTML file

When visiting localhost:8013 you should see:

A simple HTML file
// an additional line the end of every file

Transform only data with a certain URL

Just pass an options object as the second parameter to transformerProxy which has a match attribute. For example, if you want to modify only JavaScript files, you could use:

transformerProxy(transformerFunction, {match : /\.js([^\w]|$)/})

License

MIT © Philipp Otto 2014

About

A middleware component for node-http-proxy to transform the response from the proxied server.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载