http-proxy.js 733 B

1234567891011121314151617181920
  1. var httpProxy = require('http-proxy');
  2. var connect = require('connect');
  3. var injector = require('../lib/connect-injector');
  4. var proxy = httpProxy.createProxyServer();
  5. var inject = injector(function(req, res) {
  6. return res.getHeader('content-type').indexOf('text/html') === 0;
  7. }, function(data, req, res, callback) {
  8. callback(null, data.toString().replace('</body>', '<p>Powered by connect-injector</p></body>'));
  9. });
  10. var proxyMiddleware = function(req, res) {
  11. // You need to rewrite your host in order to be able to hit virtual hosts
  12. req.headers.host = 'daffl.github.io';
  13. proxy.web(req, res, {
  14. target: 'http://daffl.github.io'
  15. });
  16. };
  17. var proxyApp = connect().use(inject).use(proxyMiddleware);
  18. proxyApp.listen(8080);