Skip to content

Commit 6f3ad06

Browse files
authored
fix(twilio-run:start): changing port numbers changes output (#189)
Fixes #188. Previously, when starting up we generated the url and optionally the ngrok tunnel before we started the server. If starting then clashed with an existing server on the port we chose and a different port was selected, the display and ngrok tunnel would still point at the original port. This commit only generates the URL and ngrok tunnel once the server has started using the port that was ultimately selected.
1 parent 4a0c04b commit 6f3ad06

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/twilio-run/src/commands/start.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getDebugFunction, logger, setLogLevelByName } from '../utils/logger';
1010
import { ExternalCliOptions, sharedCliOptions } from './shared';
1111
import { CliInfo } from './types';
1212
import { getFullCommand } from './utils';
13+
import { getUrl } from '../config/start';
1314

1415
const debug = getDebugFunction('twilio-run:start');
1516

@@ -74,9 +75,15 @@ export async function handler(
7475
return new Promise((resolve, reject) => {
7576
let attempts = 1;
7677
const MAX_ATTEMPTS = 3;
77-
const serverStartedSuccessfully = async () => {
78-
printRouteInfo(config);
79-
resolve();
78+
const serverStartedSuccessfully = (port?: number) => {
79+
return async () => {
80+
if (port) {
81+
config.port = port;
82+
}
83+
config.url = await getUrl(argv, config.port);
84+
printRouteInfo(config);
85+
resolve();
86+
};
8087
};
8188
const handleServerError = async (error: ServerError) => {
8289
if (error.code === 'EADDRINUSE') {
@@ -96,7 +103,7 @@ export async function handler(
96103
attempts += 1;
97104
const server = app.listen(
98105
answers.newPortNumber,
99-
serverStartedSuccessfully
106+
serverStartedSuccessfully(answers.newPortNumber)
100107
);
101108
server.on('error', handleServerError);
102109
}
@@ -105,7 +112,7 @@ export async function handler(
105112
}
106113
};
107114

108-
const server = app.listen(config.port, serverStartedSuccessfully);
115+
const server = app.listen(config.port, serverStartedSuccessfully());
109116
server.on('error', handleServerError);
110117
});
111118
}

packages/twilio-run/src/config/start.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export async function getConfigFromCli(
168168
config.baseDir = getBaseDirectory(cli);
169169
config.env = await getEnvironment(cli, config.baseDir);
170170
config.port = getPort(cli);
171-
config.url = await getUrl(cli, config.port);
172171
config.detailedLogs = cli.detailedLogs;
173172
config.live = cli.live;
174173
config.logs = cli.logs;

0 commit comments

Comments
 (0)