feat: validate runtime configuration before mount
This commit is contained in:
+36
-7
@@ -1,11 +1,24 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
function BootstrapShell() {
|
||||
import { BootConfigError, loadRuntimeConfig } from "./load-runtime-config.js";
|
||||
|
||||
/** @param {{ environment: string }} props */
|
||||
function BootstrapShell({ environment }) {
|
||||
return (
|
||||
<main>
|
||||
<h1>Clean Architecture Frontend</h1>
|
||||
<p>런타임 계약을 불러오는 중입니다.</p>
|
||||
<p>{environment} 런타임 계약이 검증되었습니다.</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {{ supportReference: string }} props */
|
||||
function BootErrorShell({ supportReference }) {
|
||||
return (
|
||||
<main role="alert">
|
||||
<h1>애플리케이션을 시작할 수 없습니다.</h1>
|
||||
<p>지원 참조: {supportReference}</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -16,8 +29,24 @@ if (!rootElement) {
|
||||
throw new Error("Missing #root mount element");
|
||||
}
|
||||
|
||||
createRoot(rootElement).render(
|
||||
<StrictMode>
|
||||
<BootstrapShell />
|
||||
</StrictMode>,
|
||||
);
|
||||
const root = createRoot(rootElement);
|
||||
|
||||
async function boot() {
|
||||
try {
|
||||
const runtime = await loadRuntimeConfig();
|
||||
root.render(
|
||||
<StrictMode>
|
||||
<BootstrapShell environment={runtime.config.APP_ENV} />
|
||||
</StrictMode>,
|
||||
);
|
||||
} catch (error) {
|
||||
const supportReference =
|
||||
error instanceof BootConfigError
|
||||
? error.safe.supportReference
|
||||
: "boot:unknown";
|
||||
|
||||
root.render(<BootErrorShell supportReference={supportReference} />);
|
||||
}
|
||||
}
|
||||
|
||||
void boot();
|
||||
|
||||
Reference in New Issue
Block a user