Spaces:
Sleeping
Sleeping
Download ui/src/api/client.js from shancode/go-web-demo: direct link, hf CLI and curl.
- Browser
- Download file 658 Bytes
-
https://huggingface.co/spaces/shancode/go-web-demo/resolve/main/ui/src/api/client.js
- Command line
-
hf download hf://spaces/shancode/go-web-demo/ui/src/api/client.js
-
curl -L -o client.js https://huggingface.co/spaces/shancode/go-web-demo/resolve/main/ui/src/api/client.js
658 Bytes
| import axios from 'axios' | |
| const apiBase = import.meta.env.VITE_API_BASE || '/api' | |
| const api = axios.create({ | |
| baseURL: apiBase, | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| }) | |
| export const request = async (path, options = {}) => { | |
| try { | |
| const response = await api({ | |
| url: path, | |
| ...options, | |
| }) | |
| const payload = response.data || {} | |
| if (payload.code !== 0) { | |
| throw new Error(payload.msg || '请求失败') | |
| } | |
| return payload.data | |
| } catch (error) { | |
| if (error.response?.data) { | |
| const payload = error.response.data | |
| throw new Error(payload.msg || error.message) | |
| } | |
| throw error | |
| } | |
| } | |