feat: allow cockpit with docker

This commit is contained in:
Anthony Laibe 2019-01-09 15:31:34 +00:00 committed by Iuri Matias
parent 2505fa5284
commit 8efa8895aa
2 changed files with 7 additions and 6 deletions

View File

@ -1,11 +1,12 @@
import { Embark } from "../../../typings/embark";
import {canonicalHost} from "../../utils/host.js";
import {Embark} from "../../../typings/embark";
import {dockerHostSwap} from "../../utils/host.js";
import {findNextPort} from "../../utils/network";
import Server from "./server";
const utils = require("../../utils/utils.js");
const DEFAULT_PORT = 55555;
const DEFAULT_HOSTNAME = "localhost";
export default class Api {
private port!: number;
@ -16,9 +17,9 @@ export default class Api {
this.embark.events.emit("status", __("Starting API"));
findNextPort(DEFAULT_PORT).then((port) => {
this.port = port;
this.apiUrl = "http://" + canonicalHost("127.0.0.1") + ":" + this.port;
this.apiUrl = `http://${DEFAULT_HOSTNAME}:${this.port}`;
this.api = new Server(this.embark, this.port, options.plugins);
this.api = new Server(this.embark, this.port, dockerHostSwap(DEFAULT_HOSTNAME), options.plugins);
this.listenToCommands();
this.registerConsoleCommands();

View File

@ -22,7 +22,7 @@ export default class Server {
private expressInstance: expressWs.Instance;
private server?: http.Server;
constructor(private embark: Embark, private port: number, private plugins: Plugins) {
constructor(private embark: Embark, private port: number, private hostname: string, private plugins: Plugins) {
this.expressInstance = this.initApp();
}
@ -41,7 +41,7 @@ export default class Server {
return reject(new Error(message));
}
this.server = this.expressInstance.app.listen(this.port, () => {
this.server = this.expressInstance.app.listen(this.port, this.hostname, () => {
resolve();
});
});