From 73527c4c32a318044d4f06c4521f403f61a3c138 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Mon, 3 Jul 2023 06:12:21 +0800 Subject: [PATCH] Update frontend to use runtime config for laravel api --- frontend/.env.example | 1 + frontend/composables/fetch.ts | 4 +++- frontend/nuxt.config.ts | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 frontend/.env.example diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 0000000..e490c42 --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1 @@ +LARAVEL_API=http://localhost:8000 diff --git a/frontend/composables/fetch.ts b/frontend/composables/fetch.ts index 612f2fa..a5eed63 100644 --- a/frontend/composables/fetch.ts +++ b/frontend/composables/fetch.ts @@ -1,5 +1,7 @@ import type { UseFetchOptions } from 'nuxt/app' +const config = useRuntimeConfig() + const useCustomFetch = async ( path: string, options: UseFetchOptions = {} @@ -11,7 +13,7 @@ const useCustomFetch = async ( headers['X-XSRF-TOKEN'] = token.value as string } - return useFetch('http://localhost:8080' + path, { + return useFetch(config.public.laravelApi + path, { credentials: 'include', watch: false, ...options, diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts index 088595f..f716190 100644 --- a/frontend/nuxt.config.ts +++ b/frontend/nuxt.config.ts @@ -9,8 +9,7 @@ export default defineNuxtConfig({ }, runtimeConfig: { public: { - api: 'http://dev.local:8000/api', - url: 'http://dev.local:8000', + laravelApi: process.env.LARAVEL_API || 'http://localhost:8000', }, }, ssr: false,