Update frontend to use runtime config for laravel api

main
TZGyn 2 years ago
parent 8a4ad503ef
commit 73527c4c32
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -0,0 +1 @@
LARAVEL_API=http://localhost:8000

@ -1,5 +1,7 @@
import type { UseFetchOptions } from 'nuxt/app' import type { UseFetchOptions } from 'nuxt/app'
const config = useRuntimeConfig()
const useCustomFetch = async <T>( const useCustomFetch = async <T>(
path: string, path: string,
options: UseFetchOptions<T> = {} options: UseFetchOptions<T> = {}
@ -11,7 +13,7 @@ const useCustomFetch = async <T>(
headers['X-XSRF-TOKEN'] = token.value as string headers['X-XSRF-TOKEN'] = token.value as string
} }
return useFetch('http://localhost:8080' + path, { return useFetch(config.public.laravelApi + path, {
credentials: 'include', credentials: 'include',
watch: false, watch: false,
...options, ...options,

@ -9,8 +9,7 @@ export default defineNuxtConfig({
}, },
runtimeConfig: { runtimeConfig: {
public: { public: {
api: 'http://dev.local:8000/api', laravelApi: process.env.LARAVEL_API || 'http://localhost:8000',
url: 'http://dev.local:8000',
}, },
}, },
ssr: false, ssr: false,

Loading…
Cancel
Save