@@ -26,45 +26,54 @@ export class NodeFetchInjector implements OnModuleInit {
26
26
27
27
httpProviders . forEach ( ( wrapper ) => {
28
28
const prototype = wrapper . metatype . prototype ;
29
- const baseUrl : string = Reflect . getMetadata (
29
+ const baseUrl : string | undefined = Reflect . getMetadata (
30
30
HTTP_INTERFACE_METADATA ,
31
31
prototype
32
32
) ;
33
- const methodNames = this . metadataScanner . getAllMethodNames ( prototype ) ;
34
33
35
- methodNames . forEach ( ( methodName ) => {
36
- const getMetadata = this . makeMetadataGetter ( prototype , methodName ) ;
37
- const httpExchangeMetadata = getMetadata < HttpExchangeMetadata > (
38
- HTTP_EXCHANGE_METADATA
39
- ) ;
34
+ if ( typeof baseUrl === "undefined" ) {
35
+ return ;
36
+ }
40
37
41
- if ( typeof httpExchangeMetadata === "undefined" ) {
42
- return ;
43
- }
38
+ this . metadataScanner
39
+ . getAllMethodNames ( prototype )
40
+ . forEach ( ( methodName ) => {
41
+ const getMetadata = this . makeMetadataGetter ( prototype , methodName ) ;
42
+ const httpExchangeMetadata = getMetadata < HttpExchangeMetadata > (
43
+ HTTP_EXCHANGE_METADATA
44
+ ) ;
44
45
45
- const pathMetadata = getMetadata < PathVariableMetadata > (
46
- PATH_VARIABLE_METADATA
47
- ) ;
48
- const requestParamMetadata = getMetadata < RequestParamMetadata > (
49
- REQUEST_PARAM_METADATA
50
- ) ;
46
+ if ( typeof httpExchangeMetadata === "undefined" ) {
47
+ return ;
48
+ }
51
49
52
- wrapper . instance [ methodName ] = async ( ...args : any [ ] ) => {
53
- const urlBuilder = new URLBuilder (
54
- baseUrl ,
55
- httpExchangeMetadata . url ,
56
- args ,
57
- {
58
- pathParam : pathMetadata ,
59
- queryParam : requestParamMetadata ,
60
- }
50
+ const pathMetadata = getMetadata < PathVariableMetadata > (
51
+ PATH_VARIABLE_METADATA
52
+ ) ;
53
+ const requestParamMetadata = getMetadata < RequestParamMetadata > (
54
+ REQUEST_PARAM_METADATA
61
55
) ;
62
56
63
- return await this . httpClient
64
- . request ( new Request ( urlBuilder . build ( ) ) )
65
- . then ( async ( response ) => await response . json ( ) ) ;
66
- } ;
67
- } ) ;
57
+ wrapper . instance [ methodName ] = async ( ...args : any [ ] ) => {
58
+ const urlBuilder = new URLBuilder (
59
+ baseUrl ,
60
+ httpExchangeMetadata . url ,
61
+ args ,
62
+ {
63
+ pathParam : pathMetadata ,
64
+ queryParam : requestParamMetadata ,
65
+ }
66
+ ) ;
67
+
68
+ return await this . httpClient
69
+ . request (
70
+ new Request ( urlBuilder . build ( ) , {
71
+ method : httpExchangeMetadata . method ,
72
+ } )
73
+ )
74
+ . then ( async ( response ) => await response . json ( ) ) ;
75
+ } ;
76
+ } ) ;
68
77
} ) ;
69
78
}
70
79
0 commit comments