-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(logger-plugin): log target port when router option is used (#1001)
* fix(logger-plugin): log target port when router option is used * refactor(logger-plugin): extract getPort logic and add some tests * ci(spellcheck): add jsonplaceholder.typicode.com
- Loading branch information
Showing
6 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Agent } from 'node:http'; | ||
|
||
export type Sockets = Pick<Agent, 'sockets'>; | ||
|
||
/** | ||
* Get port from target | ||
* Using proxyRes.req.agent.sockets to determine the target port | ||
*/ | ||
export function getPort(sockets?: Sockets): string | undefined { | ||
return Object.keys(sockets || {})?.[0]?.split(':')[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getPort, type Sockets } from '../../../src/utils/logger-plugin'; | ||
|
||
describe('getPort()', () => { | ||
it('should return port from proxyRes.req.agent.sockets', () => { | ||
const sockets = { | ||
'jsonplaceholder.typicode.com:80:': [], | ||
} as unknown as Sockets; | ||
|
||
expect(getPort(sockets)).toBe('80'); | ||
}); | ||
|
||
it('should handle missing "sockets" from proxyRes?.req?.agent?.sockets', () => { | ||
const sockets = undefined; | ||
|
||
expect(getPort(sockets)).toBe(undefined); | ||
}); | ||
|
||
it('should handle empty "sockets" from proxyRes?.req?.agent?.sockets', () => { | ||
const sockets = {} as unknown as Sockets; | ||
|
||
expect(getPort(sockets)).toBe(undefined); | ||
}); | ||
}); |