Make hostname configurable

This commit is contained in:
Tau 2019-04-14 14:02:40 -04:00
parent 443c327680
commit f224e466c5
4 changed files with 29 additions and 3 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ bin/
node_modules/
pki/
state/
hostname.txt

25
src/hostname.ts Normal file
View File

@ -0,0 +1,25 @@
import { existsSync, readFileSync } from "fs";
import * as os from "os";
const path = "./hostname.txt";
let myHostname: string;
if (!existsSync(path)) {
const osHostname = os.hostname();
console.log(
`Hostname: ${path} does not exist, sending OS hostname "${osHostname}" to clients. This may be unreliable!`
);
myHostname = osHostname;
} else {
myHostname = readFileSync(path, { encoding: "ascii" }).trim();
console.log(
`Hostname: Sending configured hostname "${myHostname}" to clients`
);
}
export function hostname(): string {
return myHostname;
}

View File

@ -1,8 +1,7 @@
import { hostname } from "os";
import { LoadServerListRequest } from "../request/loadServerList";
import { LoadServerListResponse } from "../response/loadServerList";
import { World } from "../world";
import { hostname } from "../../hostname";
export function loadServerList(
w: World,

View File

@ -2,7 +2,8 @@ import express = require("express");
import read = require("raw-body");
import { unzipSync } from "zlib";
import { hostname } from "os";
import { hostname } from "./hostname";
const myHost = hostname();
const uris = new Map<string, string>();