-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from sima-land/38-examples-bun
Шаг 65 #38
- Loading branch information
Showing
17 changed files
with
221 additions
and
237 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
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
67 changes: 67 additions & 0 deletions
67
src/preset/node/utils/__test__/get-forwarded-headers.test.ts
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,67 @@ | ||
import type express from 'express'; | ||
import type { BaseConfig } from '../../../../config'; | ||
import { getForwardedHeaders } from '../get-forwarded-headers'; | ||
|
||
describe('getForwardedHeaders', () => { | ||
it('should return headers', () => { | ||
const config: BaseConfig = { | ||
appName: 'foo', | ||
appVersion: '0.0.1', | ||
env: 'test', | ||
}; | ||
|
||
const request: express.Request = { | ||
socket: { | ||
remoteAddress: '127.0.0.1', | ||
}, | ||
headers: { | ||
cookie: 'userid=12345', | ||
'simaland-a': 'aaa', | ||
'simaland-b': 'bbb', | ||
}, | ||
get(key: string) { | ||
return this.headers[key]; | ||
}, | ||
header(key: string) { | ||
return this.headers[key]; | ||
}, | ||
} as any; | ||
|
||
const result = getForwardedHeaders(config, request); | ||
|
||
expect(result).toEqual({ | ||
'X-Client-Ip': '127.0.0.1', | ||
'User-Agent': `simaland-foo/0.0.1`, | ||
Cookie: 'userid=12345', | ||
'simaland-a': 'aaa', | ||
'simaland-b': 'bbb', | ||
}); | ||
}); | ||
|
||
it('should return headers when lot of data is undefined', () => { | ||
const config: BaseConfig = { | ||
appName: 'foo', | ||
appVersion: '0.0.1', | ||
env: 'test', | ||
}; | ||
|
||
const request: express.Request = { | ||
socket: { | ||
remoteAddress: undefined, | ||
}, | ||
headers: {}, | ||
get(key: string) { | ||
return this.headers[key]; | ||
}, | ||
header(key: string) { | ||
return this.headers[key]; | ||
}, | ||
} as any; | ||
|
||
const result = getForwardedHeaders(config, request); | ||
|
||
expect(result).toEqual({ | ||
'User-Agent': `simaland-foo/0.0.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
4 changes: 2 additions & 2 deletions
4
src/preset/node/utils/http-server/index.ts → src/preset/node/utils/get-client-ip.ts
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
Oops, something went wrong.