@@ -78,52 +78,62 @@ export class ConfNormalizer {
7878 }
7979
8080 public static async loadRelatedTmplAndFuncFiles ( confObj : ApplicationConfig ) {
81- // todo load extra template files
82- await this . loadCodeInConf ( confObj . initContext . initFunctions , confObj ) ;
83- await this . loadCodeInConf ( confObj . initContext . functions , confObj ) ;
81+ await this . loadCodeOrTmplInConf ( confObj . initContext . initFunctions , confObj ) ;
82+ await this . loadCodeOrTmplInConf ( confObj . initContext . functions , confObj ) ;
8483
8584 for ( let route of confObj . routes ) {
8685 for ( let handler of route . extract . headerHandlers ) {
8786 if ( handler . validate ) {
88- handler . validate = await this . loadCodeInConf ( handler . validate , confObj ) as string ;
87+ handler . validate = await this . loadCodeOrTmplInConf ( handler . validate , confObj ) as string ;
8988 }
9089 }
9190 for ( let handler of route . extract . bodyHandlers ) {
9291 if ( handler . validate ) {
93- handler . validate = await this . loadCodeInConf ( handler . validate , confObj ) as string ;
92+ handler . validate = await this . loadCodeOrTmplInConf ( handler . validate , confObj ) as string ;
9493 }
9594 }
9695 for ( let relayReq of route . relay ) {
96+ relayReq . body = await this . loadCodeOrTmplInConf ( relayReq . body || '' , confObj , true ) as string ;
97+ if ( ! relayReq . headers ) {
98+ relayReq . headers = { } ;
99+ }
100+ await this . loadCodeOrTmplInConf ( relayReq . headers , confObj , true ) ;
101+ relayReq . location = await this . loadCodeOrTmplInConf ( relayReq . location , confObj , true ) as string ;
97102 if ( relayReq . interceptors ) {
98- await this . loadCodeInConf ( relayReq . interceptors , confObj ) ;
103+ await this . loadCodeOrTmplInConf ( relayReq . interceptors , confObj ) ;
99104 }
100105 }
106+ if ( ! route . response . headers ) {
107+ route . response . headers = { } ;
108+ }
109+ await this . loadCodeOrTmplInConf ( route . response . headers , confObj , true ) ;
110+ route . response . body = await this . loadCodeOrTmplInConf ( route . response . body || '' , confObj , true ) as string ;
101111 if ( route . response . interceptors ) {
102- await this . loadCodeInConf ( route . response . interceptors , confObj ) ;
112+ await this . loadCodeOrTmplInConf ( route . response . interceptors , confObj ) ;
103113 }
104114 }
105115 return confObj ;
106116 }
107117
108- private static async loadCodeInConf ( target : KVPair | string , confObj : ApplicationConfig ) {
118+ private static async loadCodeOrTmplInConf ( target : KVPair | string , confObj : ApplicationConfig , isTemplate = false ) {
109119 if ( typeof target === 'string' ) {
110- return await this . loadSingleFuncOrTmplCode ( target , confObj ) ;
120+ return await this . loadSingleFuncOrTmplCode ( target , confObj , isTemplate ) ;
111121 } else {
112122 for ( let funcName in target ) {
113123 let funcStr = target [ funcName ] . trim ( ) ;
114- target [ funcName ] = await this . loadSingleFuncOrTmplCode ( funcStr , confObj ) ;
124+ target [ funcName ] = await this . loadSingleFuncOrTmplCode ( funcStr , confObj , isTemplate ) ;
115125 }
116126 }
117127 return target ;
118128 }
119129
120- private static async loadSingleFuncOrTmplCode ( target : string , confObj : ApplicationConfig ) {
130+ private static async loadSingleFuncOrTmplCode ( target : string , confObj : ApplicationConfig , isTemplate : boolean ) {
121131 let content = target ;
122132 // load content data from files
123133 if ( target && ( target . endsWith ( '.js' ) || target . endsWith ( '.ts' ) || target . endsWith ( '.tmpl' ) ) ) {
124134 content = await ConfigManager . storage . loadSeparateContent ( target , confObj ) ;
125135 }
126- if ( target . endsWith ( '.tmpl' ) ) {
136+ if ( isTemplate ) {
127137 return content ;
128138 }
129139 // parse TS/JS function using TS Compiler
0 commit comments