Skip to content

Commit

Permalink
feat: allow cockpit with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
alaibe authored and iurimatias committed Jan 9, 2019
1 parent 2505fa5 commit 8efa889
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/lib/modules/api/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/modules/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
});
});
Expand Down

0 comments on commit 8efa889

Please sign in to comment.