@@ -5,6 +5,10 @@ import type { TesterSettings } from './testers';
55import type { Notification as AdminNotification } from '../fetch/admin' ;
66import { clientApiUrl } from '../clientApiBase' ;
77
8+ function dataApiUrl ( endpoint : string ) : string {
9+ return clientApiUrl ( `/api/data/${ endpoint } ` ) ;
10+ }
11+
812interface AvailableImage {
913 filename : string ;
1014 path : string ;
@@ -13,9 +17,7 @@ interface AvailableImage {
1317
1418async function fetchData < T > ( endpoint : string ) : Promise < T [ ] > {
1519 try {
16- const response = await fetch (
17- `${ import . meta. env . VITE_SERVER_URL } /api/data/${ endpoint } `
18- ) ;
20+ const response = await fetch ( dataApiUrl ( endpoint ) ) ;
1921 if ( ! response . ok ) {
2022 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
2123 }
@@ -73,18 +75,14 @@ export async function fetchLeaderboard(): Promise<
7375 } >
7476 >
7577> {
76- const response = await fetch (
77- `${ import . meta. env . VITE_SERVER_URL } /api/data/leaderboard`
78- ) ;
78+ const response = await fetch ( clientApiUrl ( '/api/data/leaderboard' ) ) ;
7979 if ( ! response . ok ) throw new Error ( 'Failed to fetch leaderboard' ) ;
8080 return response . json ( ) ;
8181}
8282
8383export async function getTesterSettings ( ) : Promise < TesterSettings > {
8484 try {
85- const response = await fetch (
86- `${ import . meta. env . VITE_SERVER_URL } /api/data/settings`
87- ) ;
85+ const response = await fetch ( clientApiUrl ( '/api/data/settings' ) ) ;
8886 if ( ! response . ok ) {
8987 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
9088 }
@@ -97,9 +95,7 @@ export async function getTesterSettings(): Promise<TesterSettings> {
9795}
9896
9997export async function fetchActiveNotifications ( ) : Promise < AdminNotification [ ] > {
100- const response = await fetch (
101- clientApiUrl ( '/api/data/notifications/active' )
102- ) ;
98+ const response = await fetch ( clientApiUrl ( '/api/data/notifications/active' ) ) ;
10399 if ( ! response . ok ) {
104100 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
105101 }
@@ -109,16 +105,18 @@ export async function fetchActiveNotifications(): Promise<AdminNotification[]> {
109105export async function fetchUserRanks (
110106 userId : string
111107) : Promise < Record < string , number | null > > {
112- const response = await fetch (
113- `${ import . meta. env . VITE_SERVER_URL } /api/data/ranks/${ userId } `
114- ) ;
108+ const response = await fetch ( clientApiUrl ( `/api/data/ranks/${ userId } ` ) ) ;
115109 if ( ! response . ok ) {
116110 throw new Error ( 'Failed to fetch user ranks' ) ;
117111 }
118112 return response . json ( ) ;
119113}
120114
121- export async function fetchRoute ( from : string , to : string , runway ?: string ) : Promise < {
115+ export async function fetchRoute (
116+ from : string ,
117+ to : string ,
118+ runway ?: string
119+ ) : Promise < {
122120 path : Array < { name : string ; x : number ; y : number ; type : string } > ;
123121 distance : number ;
124122 route : string ;
@@ -130,9 +128,7 @@ export async function fetchRoute(from: string, to: string, runway?: string): Pro
130128 try {
131129 const params = new URLSearchParams ( { from, to } ) ;
132130 if ( runway ) params . set ( 'runway' , runway ) ;
133- const response = await fetch (
134- `${ import . meta. env . VITE_SERVER_URL } /api/data/findRoute?${ params } `
135- ) ;
131+ const response = await fetch ( clientApiUrl ( `/api/data/findRoute?${ params } ` ) ) ;
136132 if ( ! response . ok ) {
137133 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
138134 }
0 commit comments