Skip to content

Commit

Permalink
fix upstream server config
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRay committed Mar 11, 2022
1 parent 00fd6a1 commit 031b931
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { JsonRpc, JsonRpcResult } from "node-jsonrpc-client";
import { readFileSync, writeFile, writeFileSync } from 'fs';
import * as fs from 'fs';
import TelegramBot from "node-telegram-bot-api";
import { URL } from 'url';

interface ServerDefinition {
name: string;
Expand Down Expand Up @@ -34,9 +35,11 @@ class Server {
public state: State = State.pending;
private client: JsonRpc;
private _blockHeight?: number;
private _url: URL;

constructor(config: ServerDefinition) {
this.config = config;
this._url = new URL(this.config.url);
this.client = new JsonRpc(config.url);
}

Expand All @@ -49,6 +52,16 @@ class Server {
return this.config.url;
}

public get host() {
return this._url.host;
}
public get hostname() {
return this._url.hostname;
}
public get port() {
return this._url.port;
}

public get name() {
return this.config.name;
}
Expand Down Expand Up @@ -204,7 +217,7 @@ class Monitor {

public generateNginxUpstreams() {
const serverList = this.servers.map(server =>
`server ${server.url} ${this.primaryServer === server ? '' : 'down'};`
`server ${server.host} ${this.primaryServer === server ? '' : 'down'};`
).join('\n');
const content = `upstream ${this.config.nginx.upstreamName} {
${serverList}
Expand Down

0 comments on commit 031b931

Please sign in to comment.