| 1 | import { createApp } from 'vue' |
| 2 | import type { ConfigurationData, ResponsePayload } from './types' |
| 3 | import { router } from '@/router' |
| 4 | import { UIClient } from '@/composables' |
| 5 | import App from '@/App.vue' |
| 6 | |
| 7 | const initializeApp = (config: ConfigurationData) => { |
| 8 | const app = createApp(App) |
| 9 | app.config.errorHandler = (error, instance, info) => { |
| 10 | console.error('Error:', error) |
| 11 | console.info('Vue instance:', instance) |
| 12 | console.info('Error info:', info) |
| 13 | // TODO: Add code for UI notifications or other error handling logic |
| 14 | } |
| 15 | app.config.globalProperties.$uiClient = UIClient.getInstance(config) |
| 16 | app.config.globalProperties.$uiClient.registerWSonOpenListener(async () => { |
| 17 | app.config.globalProperties.$uiClient |
| 18 | .listChargingStations() |
| 19 | .then((response: ResponsePayload) => { |
| 20 | app.config.globalProperties.$chargingStations = response.chargingStations |
| 21 | }) |
| 22 | .catch((error: Error) => { |
| 23 | console.error('Error at fetching charging stations:', error) |
| 24 | throw error |
| 25 | }) |
| 26 | .finally(() => { |
| 27 | app.use(router).mount('#app') |
| 28 | }) |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | fetch('/config.json') |
| 33 | .then(response => response.json()) |
| 34 | .catch(error => { |
| 35 | console.error('Error at fetching app configuration:', error) |
| 36 | throw error |
| 37 | }) |
| 38 | .then(config => { |
| 39 | initializeApp(config) |
| 40 | }) |
| 41 | .catch(error => { |
| 42 | console.error('Error at initializing app:', error) |
| 43 | throw error |
| 44 | }) |