Skip to content

Commit

Permalink
feat: Add option to specify server's host (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
jirimoravcik authored Nov 2, 2023
1 parent daecafb commit 5222782
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
1 change: 1 addition & 0 deletions src/anonymize_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const anonymizeProxy = (
server = new Server({
// verbose: true,
port,
host: '127.0.0.1',
prepareRequestFunction: () => {
return {
requestAuthentication: false,
Expand Down
8 changes: 5 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export type PrepareRequestFunction = (opts: PrepareRequestFunctionOpts) => Promi
export class Server extends EventEmitter {
port: number;

host?: string;

prepareRequestFunction?: PrepareRequestFunction;

authRealm: unknown;
Expand Down Expand Up @@ -138,6 +140,7 @@ export class Server extends EventEmitter {
*/
constructor(options: {
port?: number,
host?: string,
prepareRequestFunction?: PrepareRequestFunction,
verbose?: boolean,
authRealm?: unknown,
Expand All @@ -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;
Expand Down Expand Up @@ -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<void> {
const promise = new Promise<void>((resolve, reject) => {
Expand All @@ -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);
Expand Down

0 comments on commit 5222782

Please sign in to comment.