Skip to content

Commit 5222782

Browse files
authored
feat: Add option to specify server's host (#526)
1 parent daecafb commit 5222782

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ const server = new ProxyChain.Server({
3939
// Port where the server will listen. By default 8000.
4040
port: 8000,
4141

42+
// Optional host where the proxy server will listen.
43+
// If not specified, the sever listens on an unspecified IP address (0.0.0.0 in IPv4, :: in IPv6)
44+
// You can use this option to limit the access to the proxy server.
45+
host: 'localhost',
46+
4247
// Enables verbose logging
4348
verbose: true,
4449

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "proxy-chain",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
55
"main": "dist/index.js",
66
"keywords": [

src/anonymize_proxy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const anonymizeProxy = (
5656
server = new Server({
5757
// verbose: true,
5858
port,
59+
host: '127.0.0.1',
5960
prepareRequestFunction: () => {
6061
return {
6162
requestAuthentication: false,

src/server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export type PrepareRequestFunction = (opts: PrepareRequestFunctionOpts) => Promi
8888
export class Server extends EventEmitter {
8989
port: number;
9090

91+
host?: string;
92+
9193
prepareRequestFunction?: PrepareRequestFunction;
9294

9395
authRealm: unknown;
@@ -138,6 +140,7 @@ export class Server extends EventEmitter {
138140
*/
139141
constructor(options: {
140142
port?: number,
143+
host?: string,
141144
prepareRequestFunction?: PrepareRequestFunction,
142145
verbose?: boolean,
143146
authRealm?: unknown,
@@ -150,6 +153,7 @@ export class Server extends EventEmitter {
150153
this.port = options.port;
151154
}
152155

156+
this.host = options.host;
153157
this.prepareRequestFunction = options.prepareRequestFunction;
154158
this.authRealm = options.authRealm || DEFAULT_AUTH_REALM;
155159
this.verbose = !!options.verbose;
@@ -537,8 +541,6 @@ export class Server extends EventEmitter {
537541

538542
/**
539543
* Starts listening at a port specified in the constructor.
540-
* @param callback Optional callback
541-
* @return {(Promise|undefined)}
542544
*/
543545
listen(callback?: (error: NodeJS.ErrnoException | null) => void): Promise<void> {
544546
const promise = new Promise<void>((resolve, reject) => {
@@ -562,7 +564,7 @@ export class Server extends EventEmitter {
562564

563565
this.server.on('error', onError);
564566
this.server.on('listening', onListening);
565-
this.server.listen(this.port);
567+
this.server.listen(this.port, this.host);
566568
});
567569

568570
return nodeify(promise, callback);

0 commit comments

Comments
 (0)