fix(ui): open WS only once
[e-mobility-charging-stations-simulator.git] / ui / web / src / main.ts
CommitLineData
66a7748d 1import { createApp } from 'vue'
a64b9a64 2import type { ConfigurationData } from './types'
9d76f5ec
JB
3import router from '@/router'
4import { UIClient } from '@/composables'
5import App from '@/App.vue'
32de5a57 6
a64b9a64
JB
7const initializeApp = async (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)
a64b9a64
JB
16 app.use(router).mount('#app')
17}
9d76f5ec
JB
18
19fetch('/config.json')
20 .then(response => response.json())
a64b9a64
JB
21 .catch(error => {
22 console.error('Error at fetching app configuration:', error)
23 throw error
24 })
9d76f5ec 25 .then(config => {
a64b9a64
JB
26 initializeApp(config)
27 })
28 .catch(error => {
29 console.error('Error at initializing app:', error)
9e1d6e03 30 throw error
9d76f5ec 31 })