elk/server/shared.ts

27 lines
949 B
TypeScript
Raw Normal View History

2022-11-15 17:29:46 +03:00
import { $fetch } from 'ohmyfetch'
2022-11-15 18:48:23 +03:00
import type { AppInfo } from '~/types'
2022-11-15 17:29:46 +03:00
export const registeredApps: Record<string, AppInfo> = {}
2022-11-15 18:54:58 +03:00
const runtimeConfig = useRuntimeConfig()
2022-11-15 19:03:12 +03:00
const promise = $fetch(runtimeConfig.registedAppsUrl, { responseType: 'json' })
.then((r) => {
Object.assign(registeredApps, r)
// eslint-disable-next-line no-console
console.log(`\n${Object.keys(registeredApps).length} registered apps loaded from ${runtimeConfig.registedAppsUrl.split(/\/+/g)[1]}`)
// eslint-disable-next-line no-console
console.log(`${Object.keys(registeredApps).map(i => ` - ${i}`).join('\n')}\n`)
})
2022-11-15 18:48:23 +03:00
.catch((e) => {
if (process.dev)
console.error('Failed to fetch registered apps,\nyou may need to run `nr register-apps` first')
else
console.error('Failed to fetch registered apps')
console.error(e)
})
2022-11-15 17:29:46 +03:00
export async function getApp(server: string) {
await promise
return registeredApps[server]
}