Bladeren bron

chore: add @nuxt/ui dependency to package.json

ebagabee 4 maanden geleden
bovenliggende
commit
1a8d0b9bf1
8 gewijzigde bestanden met toevoegingen van 714 en 111 verwijderingen
  1. 1 0
      app/assets/main.css
  2. 67 0
      app/composables/useApi.ts
  3. 0 0
      app/types/.gitkeep
  4. 0 1
      app/types/api.ts
  5. 7 0
      app/types/nuxt.d.ts
  6. 23 0
      nuxt.config.ts
  7. 615 110
      package-lock.json
  8. 1 0
      package.json

+ 1 - 0
app/assets/main.css

@@ -1 +1,2 @@
 @import "tailwindcss";
+@import "@nuxt/ui";

+ 67 - 0
app/composables/useApi.ts

@@ -0,0 +1,67 @@
+import { useRuntimeConfig } from "nuxt/app";
+import type { ApiCallOptions, RequestBody } from "~/types/api";
+
+export const useApi = () => {
+  const config = useRuntimeConfig();
+  const apiBase = config.public.baseUrl;
+
+  const defaultHeaders = {
+    Accept: "application/json",
+    "Content-Type": "application/json",
+    "X-Requested-With": "XMLHttpRequest",
+  };
+
+  const apiCall = async <T>(
+    endpoint: string,
+    options: ApiCallOptions = {}
+  ): Promise<T> => {
+    options.retryCount = options.retryCount || 0;
+
+    try {
+      const headers: Record<string, string> = {
+        ...defaultHeaders,
+        ...options.headers,
+      };
+
+      return await $fetch<T>(endpoint, {
+        baseURL: apiBase,
+        method: options.method || "GET",
+        headers,
+        body: options.body,
+      });
+    } catch (error) {
+      if (options.retryCount < 3) {
+        options.retryCount++;
+        return await apiCall<T>(endpoint, options);
+      }
+      console.error("Erro na API:", error);
+      throw error;
+    }
+  };
+
+  const get = <T>(endpoint: string, headers?: Record<string, string>) =>
+    apiCall<T>(endpoint, { method: "GET", headers });
+
+  const post = <T>(
+    endpoint: string,
+    body?: RequestBody,
+    headers?: Record<string, string>
+  ) => apiCall<T>(endpoint, { method: "POST", body, headers });
+
+  const put = <T>(
+    endpoint: string,
+    body?: RequestBody,
+    headers?: Record<string, string>
+  ) => apiCall<T>(endpoint, { method: "PUT", body, headers });
+
+  const del = <T>(endpoint: string, headers?: Record<string, string>) =>
+    apiCall<T>(endpoint, { method: "DELETE", headers });
+
+  const patch = <T>(
+    endpoint: string,
+    body?: RequestBody,
+    headers?: Record<string, string>
+  ) => apiCall<T>(endpoint, { method: "PATCH", body, headers });
+
+  return { get, post, put, delete: del, patch };
+};

+ 0 - 0
app/interfaces/.gitkeep → app/types/.gitkeep


+ 0 - 1
app/interfaces/api.ts → app/types/api.ts

@@ -11,7 +11,6 @@ export interface ApiCallOptions {
   method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
   body?: RequestBody;
   headers?: Record<string, string>;
-  skipAuth?: boolean;
   retryCount?: number;
 }
 

+ 7 - 0
app/types/nuxt.d.ts

@@ -0,0 +1,7 @@
+declare module "@nuxt/schema" {
+  interface PublicRuntimeConfig {
+    baseUrl: string;
+  }
+}
+
+export {};

+ 23 - 0
nuxt.config.ts

@@ -3,9 +3,32 @@ import tailwindcss from "@tailwindcss/vite";
 // https://nuxt.com/docs/api/configuration/nuxt-config
 export default defineNuxtConfig({
   compatibilityDate: "2025-07-15",
+
   css: ["./app/assets/main.css"],
+
   devtools: { enabled: true },
+
   vite: {
     plugins: [tailwindcss()],
   },
+
+  app: {
+    head: {
+      title: "Skeleton",
+      link: [{ rel: "icon", type: "image/icon", href: "favicon.ico" }],
+    },
+  },
+
+  runtimeConfig: {
+    public: {
+      baseUrl: "http://localhost:8000/api",
+    },
+  },
+
+  typescript: {
+    typeCheck: false,
+    strict: false,
+  },
+
+  modules: ["@nuxt/ui"],
 });

File diff suppressed because it is too large
+ 615 - 110
package-lock.json


+ 1 - 0
package.json

@@ -10,6 +10,7 @@
     "postinstall": "nuxt prepare"
   },
   "dependencies": {
+    "@nuxt/ui": "^4.2.1",
     "@tailwindcss/vite": "^4.1.16",
     "nuxt": "^4.2.0",
     "tailwindcss": "^4.1.16",

Some files were not shown because too many files changed in this diff