feat: use runtime config for public env

This commit is contained in:
Matthieu
2025-09-17 08:16:27 +02:00
parent 95da7c72db
commit 4d2d35f360
2 changed files with 18 additions and 3 deletions

View File

@@ -2,8 +2,10 @@ import { useToast } from './useToast'
export function useApi() {
const { showSuccess, showError, showInfo } = useToast()
const API_BASE_URL = process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:3000/api'
const API_TIMEOUT = parseInt(process.env.NUXT_PUBLIC_API_TIMEOUT || '30000')
const { public: publicConfig } = useRuntimeConfig()
const API_BASE_URL = publicConfig.apiBaseUrl || 'http://localhost:3000/api'
const parsedApiTimeout = Number(publicConfig.apiTimeout ?? 30000)
const API_TIMEOUT = Number.isNaN(parsedApiTimeout) ? 30000 : parsedApiTimeout
const apiCall = async (endpoint, options = {}) => {
const url = `${API_BASE_URL}${endpoint}`
@@ -72,4 +74,4 @@ export function useApi() {
patch,
delete: del
}
}
}