66 */
77
88const BASE_URL = 'http://localhost:3847' ;
9+ const REQUEST_TIMEOUT_MS = 30_000 ;
10+
11+ async function fetchWithTimeout ( url , options = { } ) {
12+ return fetch ( url , {
13+ ...options ,
14+ signal : AbortSignal . timeout ( REQUEST_TIMEOUT_MS ) ,
15+ } ) ;
16+ }
917
1018async function testHealthCheck ( ) {
1119 console . log ( '\nTesting health check...' ) ;
12- const response = await fetch ( `${ BASE_URL } /health` ) ;
20+ const response = await fetchWithTimeout ( `${ BASE_URL } /health` ) ;
1321 const data = await response . json ( ) ;
1422 console . log ( 'Health check:' , data ) ;
1523}
1624
1725async function testVersion ( ) {
1826 console . log ( '\nTesting version endpoint...' ) ;
19- const response = await fetch ( `${ BASE_URL } /version` ) ;
27+ const response = await fetchWithTimeout ( `${ BASE_URL } /version` ) ;
2028 const data = await response . json ( ) ;
2129 console . log ( 'Version:' , data ) ;
2230}
2331
2432async function testFetchMarkets ( ) {
2533 console . log ( '\nTesting fetchMarkets (Polymarket)...' ) ;
26- const response = await fetch ( `${ BASE_URL } /api/polymarket/fetchMarkets` , {
34+ const response = await fetchWithTimeout ( `${ BASE_URL } /api/polymarket/fetchMarkets` , {
2735 method : 'POST' ,
2836 headers : { 'Content-Type' : 'application/json' } ,
2937 body : JSON . stringify ( {
@@ -42,7 +50,7 @@ async function testFetchMarkets() {
4250
4351async function testSearchMarkets ( ) {
4452 console . log ( '\nTesting searchMarkets (Kalshi)...' ) ;
45- const response = await fetch ( `${ BASE_URL } /api/kalshi/searchMarkets` , {
53+ const response = await fetchWithTimeout ( `${ BASE_URL } /api/kalshi/searchMarkets` , {
4654 method : 'POST' ,
4755 headers : { 'Content-Type' : 'application/json' } ,
4856 body : JSON . stringify ( {
@@ -63,7 +71,7 @@ async function testSearchMarkets() {
6371
6472async function testGetMarketsBySlug ( ) {
6573 console . log ( '\nTesting getMarketsBySlug (Polymarket)...' ) ;
66- const response = await fetch ( `${ BASE_URL } /api/polymarket/getMarketsBySlug` , {
74+ const response = await fetchWithTimeout ( `${ BASE_URL } /api/polymarket/getMarketsBySlug` , {
6775 method : 'POST' ,
6876 headers : { 'Content-Type' : 'application/json' } ,
6977 body : JSON . stringify ( {
@@ -84,7 +92,7 @@ async function testFetchOHLCV() {
8492 console . log ( '\nTesting fetchOHLCV (Polymarket)...' ) ;
8593
8694 // First, get a market to extract an outcome ID
87- const marketsResponse = await fetch ( `${ BASE_URL } /api/polymarket/searchMarkets` , {
95+ const marketsResponse = await fetchWithTimeout ( `${ BASE_URL } /api/polymarket/searchMarkets` , {
8896 method : 'POST' ,
8997 headers : { 'Content-Type' : 'application/json' } ,
9098 body : JSON . stringify ( {
@@ -101,7 +109,7 @@ async function testFetchOHLCV() {
101109 const outcomeId = marketsData . data [ 0 ] . outcomes [ 0 ] . id ;
102110 console . log ( ` Using outcome ID: ${ outcomeId . substring ( 0 , 20 ) } ...` ) ;
103111
104- const response = await fetch ( `${ BASE_URL } /api/polymarket/fetchOHLCV` , {
112+ const response = await fetchWithTimeout ( `${ BASE_URL } /api/polymarket/fetchOHLCV` , {
105113 method : 'POST' ,
106114 headers : { 'Content-Type' : 'application/json' } ,
107115 body : JSON . stringify ( {
0 commit comments