Skip to content

Commit

Permalink
feat: supports retrieving the port from the configuration file (eggjs…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiga committed Jan 29, 2024
1 parent 56fa39f commit d69ae0f
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/cmd/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,33 @@ export class DevCommand extends BaseCommand {
}

protected async formatEggStartOptions() {
if (!this.port) {
const defaultPort = process.env.EGG_BIN_DEFAULT_PORT ?? 7001;
debug('detect available port');
this.port = await detect(defaultPort);
if (this.port !== defaultPort) {
console.warn('[egg-bin] server port %s is in use, now using port %o', defaultPort, this.port);
}
debug(`use available port ${this.port}`);
}
this.framework = utils.getFrameworkPath({
framework: this.framework,
baseDir: this.base,
});

if (!this.port) {
const configuration = utils.getConfig({
framework: this.framework,
baseDir: this.base,
env: 'local',
});
const configuredPort = configuration?.cluster?.listen?.port;

if (configuredPort) {
this.port = configuredPort;
debug(`use port ${this.port} from configuration file`);
} else {
const defaultPort = process.env.EGG_BIN_DEFAULT_PORT ?? 7001;
debug('detect available port');
this.port = await detect(defaultPort);
if (this.port !== defaultPort) {
console.warn('[egg-bin] server port %s is in use, now using port %o', defaultPort, this.port);
}
debug(`use available port ${this.port}`);
}
}

return {
baseDir: this.base,
workers: this.workers,
Expand Down

0 comments on commit d69ae0f

Please sign in to comment.