Skip to content

Commit

Permalink
Merge pull request #619 from Danielv123/prompt-for-http-port
Browse files Browse the repository at this point in the history
Installer promt for http port
  • Loading branch information
Cooldude2606 committed May 5, 2024
2 parents e341adf + 131e45e commit 54f56d0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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",
})
Expand Down Expand Up @@ -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];
}
Expand All @@ -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]);
Expand Down
67 changes: 67 additions & 0 deletions test/integration/create.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 54f56d0

Please sign in to comment.