Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to specify server's host #526

Merged
merged 5 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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