Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download web/app/composables/useApi.ts from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 971 Bytes
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/web/app/composables/useApi.ts
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/web/app/composables/useApi.ts
-
curl -L -o useApi.ts https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/web/app/composables/useApi.ts
971 Bytes
| let authToken: string | null = null | |
| let apiKey: string | null = null | |
| export function setAuthHeader(token: string | null) { | |
| authToken = token | |
| } | |
| export function setApiKey(key: string | null) { | |
| apiKey = key | |
| } | |
| function createApiFetch() { | |
| const config = useRuntimeConfig() | |
| const publicConfig = config.public as Record<string, string> | |
| const baseURL = publicConfig.apiBaseUrl | |
| return $fetch.create({ | |
| baseURL, | |
| headers: { | |
| 'X-Client-Version': publicConfig.clientVersion || 'dev', | |
| }, | |
| onRequest({ options }) { | |
| const headers = new Headers(options.headers) | |
| if (authToken) { | |
| headers.set('Authorization', `Bearer ${authToken}`) | |
| } | |
| if (apiKey) { | |
| headers.set('x-api-key', apiKey) | |
| } | |
| options.headers = headers | |
| }, | |
| }) | |
| } | |
| export function useApi() { | |
| return { apiFetch: createApiFetch(), setAuthHeader, setApiKey } | |
| } | |
| export function useApiComposable() { | |
| return { | |
| useApi: createApiFetch, | |
| } | |
| } | |