Skip to content

Commit

Permalink
feat(api): allow explicitly port for api server in dev cmd
Browse files Browse the repository at this point in the history
via GARDEN_SERVER_PORT env variable

GARDEN_SERVER_PORT=9778 GARDEN_ENABLE_SERVER=1 garden dev
  • Loading branch information
drubin committed Dec 10, 2018
1 parent 39f1c42 commit 919e6b8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions garden-service/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { LoggerType } from "../logger/logger"
import { IntegerParameter } from "./base"
import { Command, CommandResult, CommandParams } from "./base"
import { sleep } from "../util/util"
import { startServer } from "../server/server"
import { startServer, DEFAULT_PORT } from "../server/server"

const serveArgs = {}

const serveOpts = {
port: new IntegerParameter({
help: `The port number for the Garden service to listen on.`,
defaultValue: 9777,
defaultValue: DEFAULT_PORT,
}),
}

Expand Down
4 changes: 3 additions & 1 deletion garden-service/src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export async function processModules(

// Experimental HTTP API and dashboard server.
if (process.env.GARDEN_ENABLE_SERVER === "1") {
await startServer(garden, log)
// allow overriding automatic port picking
const port = Number(process.env.GARDEN_SERVER_PORT) || undefined
await startServer(garden, log, port)
}

await restartPromise
Expand Down
2 changes: 2 additions & 0 deletions garden-service/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const DASHBOARD_BUILD_PATH = resolve(
isPkg ? process.execPath : __dirname, "..", "..", "..", "garden-dashboard", "build",
)

export const DEFAULT_PORT = 9777

/**
* Start an HTTP server that exposes commands and events for the given Garden instance.
*
Expand Down

0 comments on commit 919e6b8

Please sign in to comment.