feat: use runtime config for public env
This commit is contained in:
@@ -2,8 +2,10 @@ import { useToast } from './useToast'
|
|||||||
|
|
||||||
export function useApi() {
|
export function useApi() {
|
||||||
const { showSuccess, showError, showInfo } = useToast()
|
const { showSuccess, showError, showInfo } = useToast()
|
||||||
const API_BASE_URL = process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:3000/api'
|
const { public: publicConfig } = useRuntimeConfig()
|
||||||
const API_TIMEOUT = parseInt(process.env.NUXT_PUBLIC_API_TIMEOUT || '30000')
|
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 apiCall = async (endpoint, options = {}) => {
|
||||||
const url = `${API_BASE_URL}${endpoint}`
|
const url = `${API_BASE_URL}${endpoint}`
|
||||||
@@ -72,4 +74,4 @@ export function useApi() {
|
|||||||
patch,
|
patch,
|
||||||
delete: del
|
delete: del
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,19 @@ export default defineNuxtConfig({
|
|||||||
devServer: {
|
devServer: {
|
||||||
port: 3001,
|
port: 3001,
|
||||||
},
|
},
|
||||||
|
runtimeConfig: {
|
||||||
|
public: {
|
||||||
|
apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:3000/api',
|
||||||
|
appUrl: process.env.NUXT_PUBLIC_APP_URL || 'http://localhost:3001',
|
||||||
|
appName: process.env.NUXT_PUBLIC_APP_NAME || 'Inventory Management System',
|
||||||
|
apiTimeout: process.env.NUXT_PUBLIC_API_TIMEOUT || '30000',
|
||||||
|
requestTimeout: process.env.NUXT_PUBLIC_REQUEST_TIMEOUT || '10000',
|
||||||
|
enableDebug: process.env.NUXT_PUBLIC_ENABLE_DEBUG || 'true',
|
||||||
|
enableAnalytics: process.env.NUXT_PUBLIC_ENABLE_ANALYTICS || 'false',
|
||||||
|
csrfToken: process.env.NUXT_PUBLIC_CSRF_TOKEN || '',
|
||||||
|
logLevel: process.env.NUXT_PUBLIC_LOG_LEVEL || 'debug',
|
||||||
|
},
|
||||||
|
},
|
||||||
vite: {
|
vite: {
|
||||||
plugins: [tailwindcss()],
|
plugins: [tailwindcss()],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user