Skip to content

Commit c6a4515

Browse files
committed
[#58] remove api nuxt plugin
1 parent 5193af8 commit c6a4515

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

layouts/default.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { defineComponent } from "vue";
1818
import { useNuxtApp } from "#app";
1919
import { LayoutSidebar } from "~/src/widgets/ui";
2020
import { useEvents } from "~/src/shared/lib/use-events";
21+
import { useSettings } from "~/src/shared/lib/use-settings";
2122
import SfdumpWrap from "~/src/shared/lib/vendor/dumper";
2223
import { useSettingsStore } from "~/stores/settings";
2324
@@ -31,9 +32,12 @@ export default defineComponent({
3132
3233
const settingsStore = useSettingsStore();
3334
const { themeType, isFixedHeader } = storeToRefs(settingsStore);
34-
const { $config, $api } = useNuxtApp();
35+
const { $config } = useNuxtApp();
36+
const {
37+
api: { getVersion },
38+
} = useSettings();
3539
36-
const apiVersion = await $api.getVersion();
40+
const apiVersion = await getVersion();
3741
3842
const { events } = useEvents();
3943

nuxt.config.ts

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ export default defineNuxtConfig({
4141
},
4242
},
4343
css: ["~/assets/index.css"],
44-
plugins: [
45-
{src: '~/plugins/api.client.ts'},
46-
],
4744
modules: [
4845
'@nuxtjs/tailwindcss',
4946
'@pinia/nuxt',

src/shared/lib/use-settings/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './use-settings'
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { REST_API_URL } from "~/src/shared/lib/io";
1+
import { REST_API_URL } from "../io";
22

3-
export default defineNuxtPlugin(() => {
3+
4+
type TUseSettings = {
5+
api: {
6+
getVersion: () => Promise<string>
7+
}
8+
}
9+
10+
export const useSettings = (): TUseSettings => {
411
const getAppVersion = () => fetch(`${REST_API_URL}/api/version`)
512
.then((response) => response.json())
613
.then((response) => response?.version || 'unknown')
714
.catch(() => 'unknown');
815

916
return {
10-
provide: {
11-
api: {
12-
getVersion: getAppVersion,
13-
}
17+
api: {
18+
getVersion: getAppVersion,
1419
}
1520
}
16-
})
21+
}

0 commit comments

Comments
 (0)