skillhub/web/src/bootstrap.ts
XiaoSeS ebac94a043 feat(theme): add browser-local light and dark mode
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-09-01 17:53:41 +08:00

46 lines
1.3 KiB
TypeScript

/**
* Bootstraps runtime configuration before the React bundle mounts.
*
* Deployments inject `/runtime-config.js` at startup, and this file guarantees the app sees either
* that config or a safe fallback object before importing the main entry.
*/
import './legacy-polyfills'
import { initializeTheme } from './shared/lib/theme'
initializeTheme()
async function loadRuntimeConfig() {
await new Promise<void>((resolve, reject) => {
const script = document.createElement('script')
script.src = new URL('../runtime-config.js', import.meta.url).toString()
script.async = false
script.onload = () => resolve()
script.onerror = () => reject(new Error('Failed to load runtime config'))
document.head.appendChild(script)
})
}
function ensureRuntimeConfigFallback() {
if (!window.__SKILLHUB_RUNTIME_CONFIG__) {
window.__SKILLHUB_RUNTIME_CONFIG__ = {
apiBaseUrl: '',
appBaseUrl: '',
authDirectEnabled: 'false',
authDirectProvider: '',
authSessionBootstrapEnabled: 'false',
authSessionBootstrapProvider: '',
authSessionBootstrapAuto: 'false',
}
}
}
void (async () => {
try {
await loadRuntimeConfig()
} catch (error) {
console.error(error)
ensureRuntimeConfigFallback()
}
await import('./main')
})()