Skip to content

Commit 287c02c

Browse files
authored
Merge pull request #62 from GrinZero/replace-localhost-with-127-0-0-1-2802622098436140001
chore: replace all localhost with 127.0.0.1
2 parents 2052d4d + ffbd920 commit 287c02c

8 files changed

Lines changed: 24 additions & 24 deletions

File tree

apps/web/docs/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ register(options)
3333
### serverPort
3434

3535
- **Description**: CDP server port for Devtool
36-
- **Link**: [devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort}](devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort})
36+
- **Link**: [devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort}](devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort})
3737
- **Default value**: `5271`
3838

3939
### autoOpenDevtool

apps/web/docs/zh/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ register(options)
3333
### serverPort
3434

3535
- **描述**: CDP 服务器端口,用于 Devtool
36-
- **链接**: [devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort}](devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort})
36+
- **链接**: [devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort}](devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort})
3737
- **默认值**: `5271`
3838

3939
### autoOpenDevtool

packages/network-debugger/src/__tests__/helpers/test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function createCDPMessage(overrides?: Partial<MockCDPMessage>): MockCDPMe
9191
export function createMockRequestOptions(overrides?: Record<string, unknown>) {
9292
return {
9393
method: 'GET',
94-
hostname: 'localhost',
94+
hostname: '127.0.0.1',
9595
port: 80,
9696
path: '/',
9797
headers: {},

packages/network-debugger/src/common.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,50 +255,50 @@ describe('RequestDetail', () => {
255255
})
256256

257257
describe('isHiden', () => {
258-
test('should return true for ws://localhost/ websocket connections', () => {
258+
test('should return true for ws://127.0.0.1/ websocket connections', () => {
259259
const requestDetail = new RequestDetail()
260260
requestDetail.requestHeaders = { Upgrade: 'websocket' }
261-
requestDetail.url = 'ws://localhost/'
261+
requestDetail.url = 'ws://127.0.0.1/'
262262

263263
expect(requestDetail.isHiden()).toBe(true)
264264
})
265265

266-
test('should return true for http://localhost/ websocket connections', () => {
266+
test('should return true for http://127.0.0.1/ websocket connections', () => {
267267
const requestDetail = new RequestDetail()
268268
requestDetail.requestHeaders = { Upgrade: 'websocket' }
269-
requestDetail.url = 'http://localhost/'
269+
requestDetail.url = 'http://127.0.0.1/'
270270

271271
expect(requestDetail.isHiden()).toBe(true)
272272
})
273273

274-
test('should return false for non-localhost websocket connections', () => {
274+
test('should return false for non-127.0.0.1 websocket connections', () => {
275275
const requestDetail = new RequestDetail()
276276
requestDetail.requestHeaders = { Upgrade: 'websocket' }
277277
requestDetail.url = 'ws://example.com/'
278278

279279
expect(requestDetail.isHiden()).toBe(false)
280280
})
281281

282-
test('should return false for non-websocket localhost connections', () => {
282+
test('should return false for non-websocket 127.0.0.1 connections', () => {
283283
const requestDetail = new RequestDetail()
284284
requestDetail.requestHeaders = { 'Content-Type': 'application/json' }
285-
requestDetail.url = 'http://localhost/'
285+
requestDetail.url = 'http://127.0.0.1/'
286286

287287
expect(requestDetail.isHiden()).toBe(false)
288288
})
289289

290-
test('should return false for websocket with different localhost path', () => {
290+
test('should return false for websocket with different 127.0.0.1 path', () => {
291291
const requestDetail = new RequestDetail()
292292
requestDetail.requestHeaders = { Upgrade: 'websocket' }
293-
requestDetail.url = 'ws://localhost/api'
293+
requestDetail.url = 'ws://127.0.0.1/api'
294294

295295
expect(requestDetail.isHiden()).toBe(false)
296296
})
297297

298-
test('should return false for websocket with localhost and port', () => {
298+
test('should return false for websocket with 127.0.0.1 and port', () => {
299299
const requestDetail = new RequestDetail()
300300
requestDetail.requestHeaders = { Upgrade: 'websocket' }
301-
requestDetail.url = 'ws://localhost:8080/'
301+
requestDetail.url = 'ws://127.0.0.1:8080/'
302302

303303
expect(requestDetail.isHiden()).toBe(false)
304304
})
@@ -311,10 +311,10 @@ describe('RequestDetail', () => {
311311
expect(requestDetail.isHiden()).toBe(false)
312312
})
313313

314-
test('should return false for wss://localhost/ (secure websocket)', () => {
314+
test('should return false for wss://127.0.0.1/ (secure websocket)', () => {
315315
const requestDetail = new RequestDetail()
316316
requestDetail.requestHeaders = { Upgrade: 'websocket' }
317-
requestDetail.url = 'wss://localhost/'
317+
requestDetail.url = 'wss://127.0.0.1/'
318318

319319
expect(requestDetail.isHiden()).toBe(false)
320320
})

packages/network-debugger/src/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class RequestDetail {
4747
}
4848

4949
isHiden() {
50-
return this.isWebSocket() && ['http://localhost/', 'ws://localhost/'].includes(this.url!)
50+
return this.isWebSocket() && ['http://127.0.0.1/', 'ws://127.0.0.1/'].includes(this.url!)
5151
}
5252

5353
isWebSocket() {
@@ -99,7 +99,7 @@ export interface RegisterOptions {
9999
port?: number
100100
/**
101101
* @description CDP Server Port, used for Devtool
102-
* @link devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort}
102+
* @link devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort}
103103
* @default 5271
104104
*/
105105
serverPort?: number

packages/network-debugger/src/core/fork.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ export class MainProcess {
4949
unlinkSafe(lockFilePath)
5050
}
5151
fs.writeFileSync(lockFilePath, `${process.pid}`)
52-
const socket = new WebSocket(`ws://localhost:${props.port}`)
52+
const socket = new WebSocket(`ws://127.0.0.1:${props.port}`)
5353
socket.on('open', () => {
5454
unlinkSafe(lockFilePath)
5555
resolve(socket)
5656
})
5757
socket.on('error', () => {
5858
this.openProcess(() => {
5959
unlinkSafe(lockFilePath)
60-
const socket = new WebSocket(`ws://localhost:${props.port}`)
60+
const socket = new WebSocket(`ws://127.0.0.1:${props.port}`)
6161
socket.on('open', () => {
6262
resolve(socket)
6363
})

packages/network-debugger/src/core/request.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ describe('core/request.ts', () => {
749749
mockMainProcess as never
750750
)
751751

752-
// 使用 localhost 的隐藏 URL
752+
// 使用 127.0.0.1 的隐藏 URL
753753
const options: RequestOptions = {
754-
hostname: 'localhost',
754+
hostname: '127.0.0.1',
755755
path: '/',
756756
method: 'GET',
757757
headers: {

packages/network-debugger/src/fork/devtool/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class DevtoolServer extends BaseDevtoolServer implements IDevtoolServer {
6262
}
6363

6464
public async open() {
65-
const url = `devtools://devtools/bundled/inspector.html?ws=localhost:${this.port}`
65+
const url = `devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${this.port}`
6666
try {
6767
if (IS_DEV_MODE) {
6868
log(`In dev mode, open chrome devtool manually: ${url}`)
@@ -90,7 +90,7 @@ export class DevtoolServer extends BaseDevtoolServer implements IDevtoolServer {
9090
}
9191
try {
9292
count++
93-
resolve((await fetch(`http://localhost:${REMOTE_DEBUGGER_PORT}/json`)).json())
93+
resolve((await fetch(`http://127.0.0.1:${REMOTE_DEBUGGER_PORT}/json`)).json())
9494
clearInterval(stop)
9595
} catch {
9696
// ignore

0 commit comments

Comments
 (0)