@@ -93,19 +93,23 @@ export class TitanClient {
9393 authToken : string ;
9494 url : string ;
9595 connection : Connection ;
96+ proxyUrl ?: string ;
9697
9798 constructor ( {
9899 connection,
99100 authToken,
100101 url,
102+ proxyUrl,
101103 } : {
102104 connection : Connection ;
103105 authToken : string ;
104106 url ?: string ;
107+ proxyUrl ?: string ;
105108 } ) {
106109 this . connection = connection ;
107110 this . authToken = authToken ;
108111 this . url = url ?? TITAN_API_URL ;
112+ this . proxyUrl = proxyUrl ;
109113 }
110114
111115 /**
@@ -157,16 +161,30 @@ export class TitanClient {
157161 } ) ,
158162 } ) ;
159163
160- const response = await fetch (
161- `${ this . url } /api/v1/quote/swap?${ params . toString ( ) } ` ,
162- {
164+ let response : Response ;
165+
166+ if ( this . proxyUrl ) {
167+ // Use proxy route - send parameters in request body
168+ response = await fetch ( this . proxyUrl , {
169+ method : 'POST' ,
163170 headers : {
164- Accept : 'application/vnd.msgpack' ,
165- 'Accept-Encoding' : 'gzip, deflate, br' ,
166- Authorization : `Bearer ${ this . authToken } ` ,
171+ 'Content-Type' : 'application/json' ,
167172 } ,
168- }
169- ) ;
173+ body : JSON . stringify ( Object . fromEntries ( params . entries ( ) ) ) ,
174+ } ) ;
175+ } else {
176+ // Direct request to Titan API
177+ response = await fetch (
178+ `${ this . url } /api/v1/quote/swap?${ params . toString ( ) } ` ,
179+ {
180+ headers : {
181+ Accept : 'application/vnd.msgpack' ,
182+ 'Accept-Encoding' : 'gzip, deflate, br' ,
183+ Authorization : `Bearer ${ this . authToken } ` ,
184+ } ,
185+ }
186+ ) ;
187+ }
170188
171189 if ( ! response . ok ) {
172190 throw new Error (
@@ -268,16 +286,30 @@ export class TitanClient {
268286 } ) ,
269287 } ) ;
270288
271- const response = await fetch (
272- `${ this . url } /api/v1/quote/swap?${ params . toString ( ) } ` ,
273- {
289+ let response : Response ;
290+
291+ if ( this . proxyUrl ) {
292+ // Use proxy route - send parameters in request body
293+ response = await fetch ( this . proxyUrl , {
294+ method : 'POST' ,
274295 headers : {
275- Accept : 'application/vnd.msgpack' ,
276- 'Accept-Encoding' : 'gzip, deflate, br' ,
277- Authorization : `Bearer ${ this . authToken } ` ,
296+ 'Content-Type' : 'application/json' ,
278297 } ,
279- }
280- ) ;
298+ body : JSON . stringify ( Object . fromEntries ( params . entries ( ) ) ) ,
299+ } ) ;
300+ } else {
301+ // Direct request to Titan API
302+ response = await fetch (
303+ `${ this . url } /api/v1/quote/swap?${ params . toString ( ) } ` ,
304+ {
305+ headers : {
306+ Accept : 'application/vnd.msgpack' ,
307+ 'Accept-Encoding' : 'gzip, deflate, br' ,
308+ Authorization : `Bearer ${ this . authToken } ` ,
309+ } ,
310+ }
311+ ) ;
312+ }
281313
282314 if ( ! response . ok ) {
283315 if ( response . status === 404 ) {
0 commit comments