diff --git a/README.md b/README.md index 92dc093f..6a43c6ad 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,11 @@ const server = new ProxyChain.Server({ // Port where the server will listen. By default 8000. port: 8000, + // Optional host where the proxy server will listen. + // If not specified, the sever listens on an unspecified IP address (0.0.0.0 in IPv4, :: in IPv6) + // You can use this option to limit the access to the proxy server. + host: 'localhost', + // Enables verbose logging verbose: true, diff --git a/package.json b/package.json index 7417a5f6..ddbd4f77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "proxy-chain", - "version": "2.3.0", + "version": "2.4.0", "description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.", "main": "dist/index.js", "keywords": [ diff --git a/src/anonymize_proxy.ts b/src/anonymize_proxy.ts index e9b12d84..9771d211 100644 --- a/src/anonymize_proxy.ts +++ b/src/anonymize_proxy.ts @@ -56,6 +56,7 @@ export const anonymizeProxy = ( server = new Server({ // verbose: true, port, + host: '127.0.0.1', prepareRequestFunction: () => { return { requestAuthentication: false, diff --git a/src/server.ts b/src/server.ts index b4fe8f52..b5a802b1 100644 --- a/src/server.ts +++ b/src/server.ts @@ -88,6 +88,8 @@ export type PrepareRequestFunction = (opts: PrepareRequestFunctionOpts) => Promi export class Server extends EventEmitter { port: number; + host?: string; + prepareRequestFunction?: PrepareRequestFunction; authRealm: unknown; @@ -138,6 +140,7 @@ export class Server extends EventEmitter { */ constructor(options: { port?: number, + host?: string, prepareRequestFunction?: PrepareRequestFunction, verbose?: boolean, authRealm?: unknown, @@ -150,6 +153,7 @@ export class Server extends EventEmitter { this.port = options.port; } + this.host = options.host; this.prepareRequestFunction = options.prepareRequestFunction; this.authRealm = options.authRealm || DEFAULT_AUTH_REALM; this.verbose = !!options.verbose; @@ -537,8 +541,6 @@ export class Server extends EventEmitter { /** * Starts listening at a port specified in the constructor. - * @param callback Optional callback - * @return {(Promise|undefined)} */ listen(callback?: (error: NodeJS.ErrnoException | null) => void): Promise { const promise = new Promise((resolve, reject) => { @@ -562,7 +564,7 @@ export class Server extends EventEmitter { this.server.on('error', onError); this.server.on('listening', onListening); - this.server.listen(this.port); + this.server.listen(this.port, this.host); }); return nodeify(promise, callback);