1import axios from 'axios' 2 3const baseURL = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:5000'; 4 5console.log(`Build mode: ${process.env.NODE_ENV}, API base url ${baseURL}`); 6 7const apiClient = axios.create({ 8 baseURL, 9 withCredentials: false, 10 headers: { 11 Accept: 'application/json', 12 'Content-Type': 'application/json' 13 } 14}); 15 16export default { 17 getDownloadURLForJob(job) { 18 return `${baseURL}/download/${job.output}`; 19 }, 20 getJobs() { 21 return apiClient.get("/check") 22 }, 23 getJobById(id) { 24 return apiClient.get("/check/" + id) 25 }, 26 async getBuildList() { 27 let resp = await apiClient.get("/file"); 28 return resp.data || []; 29 }, 30 async reconstructBuildList() { 31 let resp = await apiClient.get("/reconstruct_build_list"); 32 return resp.data; 33 }, 34 uploadTarget(file, onUploadProgress) { 35 let formData = new FormData() 36 formData.append('file', file) 37 return apiClient.post("/file/" + file.name, 38 formData, 39 { 40 onUploadProgress 41 }) 42 }, 43 async postInput(input, id) { 44 try { 45 let resp = await apiClient.post( 46 '/run/' + id, JSON.stringify(input)); 47 return resp.data; 48 } catch (error) { 49 if (error.response.data) { 50 return error.response.data; 51 } else { 52 throw error; 53 } 54 } 55 } 56}