2022-11-15 15:29:46 +01:00
|
|
|
import { $fetch } from 'ohmyfetch'
|
2022-11-15 16:48:23 +01:00
|
|
|
import type { AppInfo } from '~/types'
|
2022-11-15 15:29:46 +01:00
|
|
|
|
|
|
|
export const registeredApps: Record<string, AppInfo> = {}
|
|
|
|
|
|
|
|
const promise = $fetch(process.env.APPS_JSON_URL || 'http://localhost:3000/registered-apps.json')
|
|
|
|
.then(r => Object.assign(registeredApps, r))
|
2022-11-15 16:48:23 +01: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 15:29:46 +01:00
|
|
|
|
|
|
|
export async function getApp(server: string) {
|
|
|
|
await promise
|
|
|
|
return registeredApps[server]
|
|
|
|
}
|