Skip to content

Commit 1182c35

Browse files
committed
fix(bazel): ensure PORT variable is prioritized over CLI flag
This is necessary for `server_test` to override the port that may be specified via Starlark, or the CLI flag.
1 parent 77fb8b4 commit 1182c35

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bazel/http-server/main.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ import yargs from 'yargs';
1111
import {HttpServer} from './server';
1212
import {setupBazelWatcherSupport} from './ibazel';
1313

14-
const {rootPaths, historyApiFallback, enableDevUi, environmentVariables, port, relaxCors} = yargs(
15-
process.argv.slice(2),
16-
)
14+
const {
15+
rootPaths,
16+
historyApiFallback,
17+
enableDevUi,
18+
environmentVariables,
19+
port: cliPort,
20+
relaxCors,
21+
} = yargs(process.argv.slice(2))
1722
.strict()
1823
.option('port', {
1924
type: 'number',
20-
default: process.env['PORT'] !== undefined ? Number(process.env['PORT']) : 4200,
21-
defaultDescription: '${PORT}, or 4200 if unset',
25+
default: 4200,
2226
})
2327
.option('historyApiFallback', {type: 'boolean', default: false})
2428
.option('rootPaths', {type: 'array', string: true, default: ['']})
@@ -27,6 +31,12 @@ const {rootPaths, historyApiFallback, enableDevUi, environmentVariables, port, r
2731
.option('relaxCors', {type: 'boolean', default: false})
2832
.parseSync();
2933

34+
let port = cliPort;
35+
// Process environment port always overrides the CLI, or rule attribute-specified port.
36+
if (process.env.PORT !== undefined) {
37+
port = Number(process.env.PORT);
38+
}
39+
3040
// In non-test executions, we will never allow for the browser-sync dev UI.
3141
const enableUi = process.env.TEST_TARGET === undefined && enableDevUi;
3242
const server = new HttpServer(

0 commit comments

Comments
 (0)