File tree Expand file tree Collapse file tree 2 files changed +47
-5
lines changed
packages/connectors/gcp/src Expand file tree Collapse file tree 2 files changed +47
-5
lines changed Original file line number Diff line number Diff line change 1+ import type { Request as GCPRequest } from '@google-cloud/functions-framework' ;
12import { connectorGCPHttpFunction } from '..' ;
23
34describe ( 'connector GCP' , ( ) => {
5+ const request : GCPRequest = {
6+ get : ( header : string ) => {
7+ return {
8+ origin : 'localhost' ,
9+ 'X-Real-Ip' : '127.0.0.1' ,
10+ 'User-Agent' : 'Mozilla/5.0' ,
11+ 'Accept-Language' : 'ts' ,
12+ 'Accept-Encoding' : 'gzip' ,
13+ 'X-AppEngine-Country' : 'DE' ,
14+ 'X-AppEngine-Region' : 'Hamburg' ,
15+ 'X-AppEngine-City' : 'Hamburg' ,
16+ } [ header ] ;
17+ } ,
18+ } as GCPRequest ;
19+
420 beforeEach ( ( ) => { } ) ;
521
622 test ( 'init new' , ( ) => {
7- expect ( connectorGCPHttpFunction ) . toBeDefined ( ) ;
23+ expect ( connectorGCPHttpFunction ( request ) ) . toStrictEqual ( {
24+ city : 'Hamburg' ,
25+ country : 'DE' ,
26+ encoding : 'gzip' ,
27+ ip : '127.0.0.1' ,
28+ language : 'ts' ,
29+ origin : 'localhost' ,
30+ region : 'Hamburg' ,
31+ userAgent : 'Mozilla/5.0' ,
32+ } ) ;
833 } ) ;
934} ) ;
Original file line number Diff line number Diff line change 1- import type { Request } from '@google-cloud/functions-framework' ;
1+ import type { Request } from '@elbwalker/types' ;
2+ import type { Request as GCPRequest } from '@google-cloud/functions-framework' ;
23
34export * as ConnectorGCP from './types' ;
45
5- export function connectorGCPHttpFunction ( request : Request ) : undefined {
6- console . log ( '🚀 ~ request:' , request ) ;
7- return ;
6+ export function connectorGCPHttpFunction ( request : GCPRequest ) : Request . Context {
7+ const context : Request . Context = { } ;
8+ const headerMapping : Record < string , keyof typeof context > = {
9+ origin : 'origin' ,
10+ 'X-Real-Ip' : 'ip' ,
11+ 'User-Agent' : 'userAgent' ,
12+ 'Accept-Language' : 'language' ,
13+ 'Accept-Encoding' : 'encoding' ,
14+ 'X-AppEngine-Country' : 'country' ,
15+ 'X-AppEngine-Region' : 'region' ,
16+ 'X-AppEngine-City' : 'city' ,
17+ } ;
18+
19+ Object . entries ( headerMapping ) . forEach ( ( [ header , key ] ) => {
20+ const value = request . get ( header ) ;
21+ if ( value ) context [ key ] = value ;
22+ } ) ;
23+
24+ return context ;
825}
You can’t perform that action at this time.
0 commit comments