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 2 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const server = new ProxyChain.Server({
// Port where the server will listen. By default 8000.
port: 8000,

// Hostname where the server will listen.
// optional, defaults to unspecified IP address, see e.g. https://en.wikipedia.org/wiki/IPv6_address#Unspecified_address
jirimoravcik marked this conversation as resolved.
Show resolved Hide resolved
hostname: '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
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 class Server extends EventEmitter {
port: number;

hostname?: string;

prepareRequestFunction?: PrepareRequestFunction;

authRealm: unknown;
Expand Down Expand Up @@ -138,6 +140,7 @@
*/
constructor(options: {
port?: number,
hostname?: string,
prepareRequestFunction?: PrepareRequestFunction,
verbose?: boolean,
authRealm?: unknown,
Expand All @@ -150,6 +153,7 @@
this.port = options.port;
}

this.hostname = options.hostname;
this.prepareRequestFunction = options.prepareRequestFunction;
this.authRealm = options.authRealm || DEFAULT_AUTH_REALM;
this.verbose = !!options.verbose;
Expand All @@ -172,7 +176,7 @@
log(connectionId: unknown, str: string): void {
if (this.verbose) {
const logPrefix = connectionId ? `${String(connectionId)} | ` : '';
console.log(`ProxyServer[${this.port}]: ${logPrefix}${str}`);

Check warning on line 179 in src/server.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
}
}

Expand Down Expand Up @@ -537,8 +541,6 @@

/**
* 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 @@

this.server.on('error', onError);
this.server.on('listening', onListening);
this.server.listen(this.port);
this.server.listen(this.port, this.hostname);
});

return nodeify(promise, callback);
Expand Down
Loading