Skip to content

Commit

Permalink
[#58] remove api nuxt plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreezag committed Feb 11, 2024
1 parent 5193af8 commit c6a4515
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
8 changes: 6 additions & 2 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { defineComponent } from "vue";
import { useNuxtApp } from "#app";
import { LayoutSidebar } from "~/src/widgets/ui";
import { useEvents } from "~/src/shared/lib/use-events";
import { useSettings } from "~/src/shared/lib/use-settings";
import SfdumpWrap from "~/src/shared/lib/vendor/dumper";
import { useSettingsStore } from "~/stores/settings";
Expand All @@ -31,9 +32,12 @@ export default defineComponent({
const settingsStore = useSettingsStore();
const { themeType, isFixedHeader } = storeToRefs(settingsStore);
const { $config, $api } = useNuxtApp();
const { $config } = useNuxtApp();
const {
api: { getVersion },
} = useSettings();
const apiVersion = await $api.getVersion();
const apiVersion = await getVersion();
const { events } = useEvents();
Expand Down
3 changes: 0 additions & 3 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export default defineNuxtConfig({
},
},
css: ["~/assets/index.css"],
plugins: [
{src: '~/plugins/api.client.ts'},
],
modules: [
'@nuxtjs/tailwindcss',
'@pinia/nuxt',
Expand Down
1 change: 1 addition & 0 deletions src/shared/lib/use-settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './use-settings'
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { REST_API_URL } from "~/src/shared/lib/io";
import { REST_API_URL } from "../io";

export default defineNuxtPlugin(() => {

type TUseSettings = {
api: {
getVersion: () => Promise<string>
}
}

export const useSettings = (): TUseSettings => {
const getAppVersion = () => fetch(`${REST_API_URL}/api/version`)
.then((response) => response.json())
.then((response) => response?.version || 'unknown')
.catch(() => 'unknown');

return {
provide: {
api: {
getVersion: getAppVersion,
}
api: {
getVersion: getAppVersion,
}
}
})
}

0 comments on commit c6a4515

Please sign in to comment.