added feature that allows client to work directly with ip and ports

This commit is contained in:
2025-11-04 14:53:44 -05:00
parent 470f510701
commit fa04b7e9da

View File

@@ -45,6 +45,9 @@ export class TrytonClient {
/**
* Create a new Tryton client
* @param config Configuration object
* @param config.hostname - Hostname or IP address. Can include port (e.g., "46.62.242.210:8090")
* @param config.port - Port number (ignored if hostname includes port)
*/
constructor(config: TrytonClientConfig) {
const {
@@ -69,10 +72,20 @@ export class TrytonClient {
this.useHttps = port === 443 || port === 8443;
}
// Handle IP:Port format (e.g., "46.62.242.210:8090")
if (this.hostname.includes(":") && !this.hostname.startsWith("http")) {
const [ip, hostPort] = this.hostname.split(":");
this.hostname = ip;
this.port = parseInt(hostPort, 10);
// Determine https based on extracted port
this.useHttps = this.port === 443 || this.port === 8443;
} else {
this.port = port;
}
this.database = database;
this.username = username;
this.password = password || ""; // Empty string if not provided
this.port = port;
this.language = language;
this.options = options;
this.connection = null;
@@ -81,6 +94,7 @@ export class TrytonClient {
/**
* Alternative constructor for backward compatibility
* Note: If hostname includes port (IP:Port), the port parameter will be ignored
*/
static create(
hostname: string,