Merge pull request #619 from Danielv123/prompt-for-http-port

Installer promt for http port
This commit is contained in:
Cooldude2606 authored and GitHub committed 2024-05-05 20:39:25 +01:00
commit 54f56d0ecd
2 files changed
+92

No files matched your search

+25
View File
@@ -551,6 +551,25 @@ async function inquirerMissingArgs(args) {
},
},
], answers);
if (args.httpPort) { answers.httpPort = args.httpPort; }
answers = await inquirer.prompt([
{
type: "input",
name: "httpPort",
message: "HTTP port to listen on",
default: 8080,
validate: input => {
if (!input) {
return "May not be empty";
}
if (!Number.isInteger(Number(input))) {
return "Must be a number";
}
return true;
},
},
], answers);
}
if (answers.mode === "host") {
@@ -775,6 +794,9 @@ async function main() {
.option("admin", {
nargs: 1, describe: "Admin account name [standalone/controller]", type: "string",
})
.option("http-port", {
nargs: 1, describe: "HTTP port to listen on [standalone/controller]", type: "number",
})
.option("host-name", {
nargs: 1, describe: "Host name [host]", type: "string",
})
@@ -854,6 +876,7 @@ async function main() {
if (["standalone", "controller"].includes(answers.mode)) {
logger.info("Setting up controller");
await execController(["bootstrap", "create-admin", answers.admin]);
await execController(["config", "set", "controller.http_port", answers.httpPort]);
let result = await execController(["bootstrap", "generate-user-token", answers.admin]);
adminToken = result.stdout.split("\n").slice(-2)[0];
}
@@ -868,6 +891,8 @@ async function main() {
result = await execController(["bootstrap", "generate-host-token", hostId]);
let hostToken = result.stdout.split("\n").slice(-2)[0];
// Default to localhost on correct port for host in standalone mode
await execHost(["config", "set", "host.controller_url", `http://localhost:${answers.httpPort}`]);
await execHost(["config", "set", "host.controller_token", hostToken]);
await execHost(["config", "set", "host.public_address", answers.publicAddress]);
await execHost(["config", "set", "host.factorio_directory", answers.factorioDir]);
+67
View File
@@ -0,0 +1,67 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const jwt = require("jsonwebtoken");
const path = require("path");
const events = require("events");
const phin = require("phin");
const child_process = require("child_process");
const util = require("util");
const cwd = path.join("temp", "test_integration");
async function exec(command, options = {}) {
// Uncomment to show commands run in tests
// console.log(command);
options = { cwd, ...options };
return await util.promisify(child_process.exec)(command, options);
}
describe("Integration of create tool", function () {
beforeEach(async function () {
await fs.ensureDir(cwd);
});
afterEach(async function () {
await fs.remove(cwd);
});
it("should create a new standalone installation", async function () {
this.skip();
await exec([
"node ../../packages/create",
"--mode standalone",
"--admin Danielv123",
"--http-port 8099",
"--host-name localhost",
"--public-address localhost",
"--factorio-dir test/factorio",
"--plugins --",
].join(" "));
// Check that the generated config is correct
const controllerConfig = await fs.readJson(path.join(cwd, "config-controller.json"));
assert.equal(controllerConfig["controller.http_port"], 8099);
const hostConfig = await fs.readJson(path.join(cwd, "config-host.json"));
assert.equal(hostConfig["host.name"], "local");
assert.equal(hostConfig["host.public_address"], "localhost");
assert.equal(hostConfig["host.factorio_directory"], "test/factorio");
assert.equal(hostConfig["host.controller_url"], "http://localhost:8099");
}).timeout(1200000);
it("should create a new controller installation", async function () {
this.skip();
await exec([
"node ../../packages/create",
"--mode controller",
"--admin Danielv123",
"--http-port 8099",
"--public-address localhost",
"--plugins --",
].join(" "));
// Check that the generated config is correct
const controllerConfig = await fs.readJson(path.join(cwd, "config-controller.json"));
assert.equal(controllerConfig["controller.http_port"], 8099);
await assert.rejects(fs.readJson(path.join(cwd, "config-host.json")));
}).timeout(60000);
});