Skip to content

Commit

Permalink
Only search for free port once
Browse files Browse the repository at this point in the history
We already do that in `normalizeOptions` now
  • Loading branch information
marvinhagemeister committed Mar 27, 2021
1 parent 5f648f3 commit c906736
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-trains-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wmr': patch
---

Only search for free port once in dev mode
15 changes: 1 addition & 14 deletions packages/wmr/src/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import server from './server.js';
import wmrMiddleware from './wmr-middleware.js';
import { getFreePort, getServerAddresses, isPortFree } from './lib/net-utils.js';
import { getServerAddresses } from './lib/net-utils.js';
import { normalizeOptions } from './lib/normalize-options.js';
import { setCwd } from './plugins/npm-plugin/registry.js';
import { formatBootMessage } from './lib/output-utils.js';
Expand All @@ -21,19 +21,6 @@ export default async function start(options = {}) {

options = await normalizeOptions(options, 'start');

// Don't use another free port if the user explicitely
// requested a specific one.
const userPort = options.port || process.env.PORT;
if (userPort !== undefined) {
if (await isPortFree(+userPort)) {
options.port = +userPort;
} else {
throw new Error(`Another process is already running on port ${userPort}. Please choose a different port.`);
}
} else {
options.port = await getFreePort(8080);
}

options.host = options.host || process.env.HOST;

options.middleware = [].concat(
Expand Down

0 comments on commit c906736

Please sign in to comment.