feat: make server health_check_port optional

This commit is contained in:
Jonathan Barrow 2026-01-12 12:33:29 -05:00
parent 84094ed232
commit 38c6e6ecdf
No known key found for this signature in database
GPG Key ID: 2A7DAA6DED5A77E5
2 changed files with 15 additions and 5 deletions

View File

@ -64,7 +64,10 @@ const ServerSchema = new Schema<IServer, ServerModel, IServerMethods>({
maintenance_mode: Boolean,
device: Number,
aes_key: String,
health_check_port: Number
health_check_port: {
type: Number,
required: false
}
});
ServerSchema.plugin(uniqueValidator, { message: '{PATH} already in use.' });
@ -75,9 +78,18 @@ ServerSchema.method('getServerConnectInfo', async function (): Promise<IServerCo
throw new Error(`No IP configured for server ${this._id}`);
}
const randomIP = ipList[Math.floor(Math.random() * ipList.length)];
if (!this.health_check_port) {
return {
ip: randomIP,
port: this.port
};
}
const healthCheckTargets = ipList.map(ip => ({
host: ip,
port: this.health_check_port
port: this.health_check_port!
}));
let target: string | undefined;
@ -91,8 +103,6 @@ ServerSchema.method('getServerConnectInfo', async function (): Promise<IServerCo
// TODO - Handle this
}
const randomIP = ipList[Math.floor(Math.random() * ipList.length)];
return {
ip: target || randomIP, // * Just use a random IP if nothing responded in time and Hope For The Best:tm:
port: this.port

View File

@ -13,7 +13,7 @@ export interface IServer {
maintenance_mode: boolean;
device: number;
aes_key: string;
health_check_port: number;
health_check_port?: number;
}
export interface IServerConnectInfo {