added useAPI for backend communication
This commit is contained in:
parent
e9403fea68
commit
62800c9776
3 changed files with 26 additions and 2 deletions
19
services/frontend/composables/useAPI.ts
Normal file
19
services/frontend/composables/useAPI.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import type { UseFetchOptions } from "nuxt/app";
|
||||
|
||||
export function useAPI<T>(
|
||||
endpoint: string,
|
||||
options?: UseFetchOptions<T>,
|
||||
) {
|
||||
if (!endpoint.startsWith("/")) {
|
||||
endpoint = `/${endpoint}`
|
||||
}
|
||||
|
||||
const cfg = useRuntimeConfig()
|
||||
|
||||
const fullUrl = `${cfg.public.backendUrl}${endpoint}`
|
||||
|
||||
return useFetch(
|
||||
fullUrl,
|
||||
{...options}
|
||||
)
|
||||
}
|
|
@ -8,6 +8,11 @@ export default defineNuxtConfig({
|
|||
build: {
|
||||
transpile: ['vuetify'],
|
||||
},
|
||||
runtimeConfig: {
|
||||
public: {
|
||||
backendUrl: process.env.BACKEND_URL ?? "http://localhost:8000"
|
||||
},
|
||||
},
|
||||
modules: [
|
||||
(_options, nuxt) => {
|
||||
nuxt.hooks.hook('vite:extendConfig', (config) => {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<template>
|
||||
Index file
|
||||
</template>
|
||||
Index file
|
||||
</template>
|
||||
|
|
Loading…
Reference in a new issue