import * as Domain from "@app/domain"; import * as Types from "@app/types"; import * as React from "react"; import * as ReactDOM from "react-dom"; import * as App from "./App"; const DEBUG_API_SERVER = "http://localhost:7000/api"; const getConfig = async (): Promise => { const configUrl = "http://localhost:7000/config.json"; // window.location.href + "config.json"; try { const res = await fetch(configUrl); return res.json(); } catch (e) { console.error(e); return undefined; } }; const debugMode = async (url: string): Promise => { try { const res = await fetch(url); render(await res.json()); } catch (e) { console.error(e); alert("Insufficient parameters of initialize. If debug mode, start debug server with @code-dependency/cli."); } }; const getCsrProps = (): Types.CsrProps | undefined => { const csrProps = (window as any).__INITIAL_STATE__; if (!!csrProps && typeof csrProps !== "string") { return csrProps; } return undefined; }; const render = (csrProps?: Types.CsrProps, config?: Types.StaticConfig) => { const reducers = Domain.createReducers({ csrProps, config }); ReactDOM.render(, document.getElementById("root")); }; export const initialize = async () => { const csrProps = getCsrProps(); const config = await getConfig(); if (!csrProps && !config) { debugMode(DEBUG_API_SERVER); } else { render(csrProps, config); } return Promise.resolve(); };