73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import * as Vue from 'vue'
|
|
import * as VueRouterLib from 'vue-router'
|
|
import * as PiniaLib from 'pinia'
|
|
import { createApp } from 'vue'
|
|
import { createPinia } from 'pinia'
|
|
import { PerfectScrollbarPlugin } from 'vue3-perfect-scrollbar'
|
|
import { useModuleStore } from '@KTXC/stores/moduleStore'
|
|
import { useTenantStore } from '@KTXC/stores/tenantStore'
|
|
import { useUserStore } from '@KTXC/stores/userStore'
|
|
import { fetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper'
|
|
import { initializeModules } from '@KTXC/utils/modules'
|
|
import App from './App.vue'
|
|
import router from './router'
|
|
import vuetify from './plugins/vuetify/index'
|
|
import '@KTXC/scss/style.scss'
|
|
|
|
// Material Design Icons (Vuetify mdi icon set)
|
|
import '@mdi/font/css/materialdesignicons.min.css'
|
|
|
|
// google-fonts
|
|
import '@fontsource/public-sans/index.css'
|
|
|
|
const app = createApp(App)
|
|
const pinia = createPinia()
|
|
app.use(pinia)
|
|
app.use(PerfectScrollbarPlugin)
|
|
app.use(vuetify)
|
|
|
|
// Note: Router is registered AFTER modules are loaded to prevent premature route matching
|
|
|
|
const globalWindow = window as typeof window & {
|
|
[key: string]: unknown
|
|
}
|
|
|
|
globalWindow.Vue = Vue
|
|
globalWindow.vue = Vue
|
|
globalWindow.VueRouter = VueRouterLib
|
|
globalWindow.Pinia = PiniaLib as unknown
|
|
|
|
// Bootstrap initial private UI state (modules, tenant, user) before mounting
|
|
(async () => {
|
|
const moduleStore = useModuleStore();
|
|
const tenantStore = useTenantStore();
|
|
const userStore = useUserStore();
|
|
|
|
try {
|
|
const payload = await fetchWrapper.get('/init');
|
|
moduleStore.init(payload?.modules ?? {});
|
|
tenantStore.init(payload?.tenant ?? null);
|
|
userStore.init(payload?.user ?? {});
|
|
|
|
// Initialize registered modules (following reference app's bootstrap pattern)
|
|
await initializeModules(app);
|
|
|
|
// Add 404 catch-all route AFTER all modules are loaded
|
|
// This ensures module routes are registered before the catch-all
|
|
router.addRoute({
|
|
name: 'NotFound',
|
|
path: '/:pathMatch(.*)*',
|
|
component: () => import('@KTXC/views/pages/maintenance/error/Error404Page.vue')
|
|
});
|
|
|
|
// Register router AFTER modules are loaded
|
|
app.use(router);
|
|
|
|
await router.isReady();
|
|
// Home redirect handled by router beforeEnter
|
|
app.mount('#app');
|
|
} catch (e) {
|
|
console.error('Bootstrap failed:', e);
|
|
}
|
|
})();
|