Spaces:
Running
Running
File size: 1,147 Bytes
a1f1bf8 ed37070 0b598b9 a1f1bf8 0b598b9 a1f1bf8 0b598b9 98847a8 ed37070 0b598b9 a1f1bf8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
const VITE_API_SERVER_URL = import.meta.env.VITE_API_SERVER_URL || ''
console.log(`API Server URL: ${VITE_API_SERVER_URL}`)
class API {
static async fetchIndex(): Promise<string> {
const response = await fetch(VITE_API_SERVER_URL + '/')
if (!response.ok) throw new Error('Failed to fetch index.html')
return response.text()
}
static async fetchStaticFile(path: string): Promise<string> {
const response = await fetch(`${VITE_API_SERVER_URL}/${path}`)
if (!response.ok) throw new Error(`Failed to fetch ${path}`)
return response.text()
}
// Rename the method to fetchExamplesByType
static fetchExamplesByType(type: 'image' | 'audio' | 'video'): Promise<any> {
return fetch(`${VITE_API_SERVER_URL}/examples/${type}`).then((response) => {
if (!response.ok) {
throw new Error(`Failed to fetch examples of type ${type}`)
}
return response.json()
})
}
// Add a method to fetch a resource via the proxy endpoint to bypass CORS issues
static getProxiedUrl(url: string): string {
return `${VITE_API_SERVER_URL}/proxy/${encodeURIComponent(url)}`
}
}
export default API
|