Load a config.json
Fetched at runtime, or bundled at build time.
To bundle the file instead,
import config from './config.json' with { type: 'json' } and keep the
addRelativeUris call, against the URL its data is served from. The embedded
app does not load a config’s plugins: loadPlugins does, its baseUri
resolving a relative plugin URL against the config.
Show source · 28 linesHide source · 28 lines
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
import {
JBrowseApp,
createViewStateAsync,
loadPlugins,
useCreateViewState,
} from '@jbrowse/react-app2'
const configUrl =
'https://jbrowse.org/code/jb2/main/test_data/volvox/config.json'
async function build() {
const response = await fetch(configUrl)
if (!response.ok) {
throw new Error(`HTTP ${response.status} fetching config ${configUrl}`)
}
const config = await response.json()
addRelativeUris(config, new URL(configUrl))
const plugins = await loadPlugins(config.plugins ?? [], {
baseUri: configUrl,
})
return createViewStateAsync({ config, plugins })
}
export default function FetchConfigJson() {
const state = useCreateViewState(build)
return state ? <JBrowseApp viewState={state} /> : null
}