http-proxy.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Use explicit /index.js to help browserify negociation in require '/lib/http-proxy' (!)
  2. var ProxyServer = require('./http-proxy/index.js').Server;
  3. /**
  4. * Creates the proxy server.
  5. *
  6. * Examples:
  7. *
  8. * httpProxy.createProxyServer({ .. }, 8000)
  9. * // => '{ web: [Function], ws: [Function] ... }'
  10. *
  11. * @param {Object} Options Config object passed to the proxy
  12. *
  13. * @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests
  14. *
  15. * @api public
  16. */
  17. function createProxyServer(options) {
  18. /*
  19. * `options` is needed and it must have the following layout:
  20. *
  21. * {
  22. * target : <url string to be parsed with the url module>
  23. * forward: <url string to be parsed with the url module>
  24. * agent : <object to be passed to http(s).request>
  25. * ssl : <object to be passed to https.createServer()>
  26. * ws : <true/false, if you want to proxy websockets>
  27. * xfwd : <true/false, adds x-forward headers>
  28. * secure : <true/false, verify SSL certificate>
  29. * toProxy: <true/false, explicitly specify if we are proxying to another proxy>
  30. * prependPath: <true/false, Default: true - specify whether you want to prepend the target's path to the proxy path>
  31. * ignorePath: <true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request>
  32. * localAddress : <Local interface string to bind for outgoing connections>
  33. * changeOrigin: <true/false, Default: false - changes the origin of the host header to the target URL>
  34. * auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
  35. * hostRewrite: rewrites the location hostname on (301/302/307/308) redirects, Default: null.
  36. * autoRewrite: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.
  37. * protocolRewrite: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
  38. * }
  39. *
  40. * NOTE: `options.ws` and `options.ssl` are optional.
  41. * `options.target and `options.forward` cannot be
  42. * both missing
  43. * }
  44. */
  45. return new ProxyServer(options);
  46. }
  47. ProxyServer.createProxyServer = createProxyServer;
  48. ProxyServer.createServer = createProxyServer;
  49. ProxyServer.createProxy = createProxyServer;
  50. /**
  51. * Export the proxy "Server" as the main export.
  52. */
  53. module.exports = ProxyServer;