http-proxy.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * preserveHeaderKeyCase: <true/false, Default: false - specify whether you want to keep letter case of response header key >
  35. * auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
  36. * hostRewrite: rewrites the location hostname on (201/301/302/307/308) redirects, Default: null.
  37. * autoRewrite: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.
  38. * protocolRewrite: rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.
  39. * }
  40. *
  41. * NOTE: `options.ws` and `options.ssl` are optional.
  42. * `options.target and `options.forward` cannot be
  43. * both missing
  44. * }
  45. */
  46. return new ProxyServer(options);
  47. }
  48. ProxyServer.createProxyServer = createProxyServer;
  49. ProxyServer.createServer = createProxyServer;
  50. ProxyServer.createProxy = createProxyServer;
  51. /**
  52. * Export the proxy "Server" as the main export.
  53. */
  54. module.exports = ProxyServer;