Skip to content

Commit ad2ede7

Browse files
Merge pull request #6269 from Shopify/fix-localhost-inconsistency
Use localhost for all port detection + serving
2 parents 0863957 + 89813a6 commit ad2ede7

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

packages/cli-kit/src/public/node/tcp.test.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('checkPortAvailability', () => {
8080

8181
// Then
8282
expect(result).toBe(true)
83-
expect(port.checkPort).toHaveBeenCalledWith(portNumber, undefined)
83+
expect(port.checkPort).toHaveBeenCalledWith(portNumber, 'localhost')
8484
})
8585

8686
test('returns false when port is not available', async () => {
@@ -93,23 +93,6 @@ describe('checkPortAvailability', () => {
9393

9494
// Then
9595
expect(result).toBe(false)
96-
expect(port.checkPort).toHaveBeenCalledWith(portNumber, undefined)
97-
})
98-
99-
test('uses 0.0.0.0 as host when HOST env var is set', async () => {
100-
// Given
101-
const portNumber = 3000
102-
vi.stubEnv('HOST', 'localhost')
103-
vi.mocked(port.checkPort).mockResolvedValue(portNumber)
104-
105-
// When
106-
const result = await checkPortAvailability(portNumber)
107-
108-
// Then
109-
expect(result).toBe(true)
110-
expect(port.checkPort).toHaveBeenCalledWith(portNumber, '0.0.0.0')
111-
112-
// Cleanup
113-
vi.unstubAllEnvs()
96+
expect(port.checkPort).toHaveBeenCalledWith(portNumber, 'localhost')
11497
})
11598
})

packages/cli-kit/src/public/node/tcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export async function checkPortAvailability(portNumber: number): Promise<boolean
5050

5151
function host(): string | undefined {
5252
// The get-port-please library does not work as expected when HOST env var is defined,
53-
// so explicitly set the host to 0.0.0.0 to avoid conflicts
54-
return process.env.HOST ? '0.0.0.0' : undefined
53+
// so explicitly set the host to localhost to avoid conflicts
54+
return 'localhost'
5555
}
5656

5757
/**

0 commit comments

Comments
 (0)