You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. pac-resolver
  2. ============
  3. ### Generates an asynchronous resolver function from a [PAC file][pac-wikipedia]
  4. [![Build Status](https://travis-ci.org/TooTallNate/node-pac-resolver.svg?branch=master)](https://travis-ci.org/TooTallNate/node-pac-resolver)
  5. This module accepts a JavaScript String of code, which is meant to be a
  6. [PAC proxy file][pac-wikipedia], and returns a generated asynchronous
  7. `FindProxyForURL()` function.
  8. Installation
  9. ------------
  10. Install with `npm`:
  11. ``` bash
  12. $ npm install pac-resolver
  13. ```
  14. Example
  15. -------
  16. Given the PAC proxy file named `proxy.pac`:
  17. ``` js
  18. function FindProxyForURL(url, host) {
  19. if (isInNet(myIpAddress(), "10.1.10.0", "255.255.255.0")) {
  20. return "PROXY 1.2.3.4:8080";
  21. } else {
  22. return "DIRECT";
  23. }
  24. }
  25. ```
  26. You can consume this PAC file with `pac-resolver` like so:
  27. ``` js
  28. var fs = require('fs');
  29. var pac = require('pac-resolver');
  30. var FindProxyForURL = pac(fs.readFileSync('proxy.pac'));
  31. FindProxyForURL('http://foo.com/').then((res) => {
  32. console.log(res);
  33. // "DIRECT"
  34. });
  35. ```
  36. API
  37. ---
  38. ### pac(String jsStr[, Object options]) → Function
  39. Returns an asynchronous `FindProxyForURL()` function based off of the given JS
  40. string `jsStr` PAC proxy file. An optional `options` object may be passed in which
  41. respects the following options:
  42. * `filename` - String - the filename to use in error stack traces. Defaults to `proxy.pac`.
  43. * `sandbox` - Object - a map of functions to include in the sandbox of the
  44. JavaScript environment where the JS code will be executed. i.e. if you wanted to
  45. include the common `alert` function you could pass `alert: console.log`. For
  46. async functions, you must set the `async = true` property on the function
  47. instance, and the JS code will be able to invoke the function as if it were
  48. synchronous.
  49. License
  50. -------
  51. (The MIT License)
  52. Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
  53. Permission is hereby granted, free of charge, to any person obtaining
  54. a copy of this software and associated documentation files (the
  55. 'Software'), to deal in the Software without restriction, including
  56. without limitation the rights to use, copy, modify, merge, publish,
  57. distribute, sublicense, and/or sell copies of the Software, and to
  58. permit persons to whom the Software is furnished to do so, subject to
  59. the following conditions:
  60. The above copyright notice and this permission notice shall be
  61. included in all copies or substantial portions of the Software.
  62. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  63. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  64. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  65. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  66. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  67. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  68. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  69. [pac-file-docs]: https://web.archive.org/web/20070602031929/http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
  70. [pac-wikipedia]: http://wikipedia.org/wiki/Proxy_auto-config