UNPKG

infrastructure-components

Version:

Infrastructure-Components configure the infrastructure of your React-App as part of your React-Components.

73 lines (67 loc) 3.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const iso_libs_1 = require("../libs/iso-libs"); // this must be imported to allow async-functions within an AWS lambda environment // see: https://github.com/babel/babel/issues/5085 require("@babel/polyfill"); const react_dom_1 = require("react-dom"); const routed_app_1 = require("./routed-app"); const types_1 = __importDefault(require("../types")); const loader_1 = require("../libs/loader"); const datalayer_integration_1 = require("./datalayer-integration"); /** * * this module must not import anything that does not exist in web-mode, e.g. fs * * Creates the main Client WebApp. The `./src/client/index.tsx` module exports the result of calling this function * This serves as Entry-Point specified in the [[webpackConfigClient]] * * This function takes the data that is generated from the server endpoint */ const createClientWebApp = () => { var basename = iso_libs_1.getBasename(); /* if (typeof window != 'undefined' && window.__BASENAME__) { basename = window.__BASENAME__; // we do not delete the basename here, because we may need it at different places //delete window.__BASENAME__; }*/ // load the IsomorphicComponent // we must load it directly from the module here, to enable the aliad of the config_file_path const isoConfig = loader_1.loadConfigurationFromModule(require('__CONFIG_FILE_PATH__'), loader_1.INFRASTRUCTURE_MODES.RUNTIME); // let's extract it from the root configuration const webApp = loader_1.extractObject(isoConfig, types_1.default.INFRASTRUCTURE_TYPE_CLIENT, __ISOMORPHIC_ID__); /* const parsedUrl = req.url.indexOf("?") >= 0 ? req.url.substring(0, req.url.indexOf("?")) : req.url; console.log("parsedUrl: ", parsedUrl); ////////// TODO refactor var foundPath = undefined; // match request url to our React Router paths and grab the path-params let matchResult = clientApp.routes.find( ({ path, exact }) => { foundPath = matchPath(parsedUrl, { path, exact, strict: false } ) return foundPath }) || {}; let { path } = matchResult; //console.log("found: ", foundPath); console.log("server: path params: ", foundPath ? foundPath.params : "---");*/ const preloadedState = typeof window != 'undefined' && window.__ISOMORPHICSTATE__ ? window.__ISOMORPHICSTATE__ : undefined; const preloadedFiles = typeof window != 'undefined' && window.__RENDERLISTSTATE__ ? window.__RENDERLISTSTATE__ : undefined; // when we have a datalayer, we can hydrate the state! const fHydrate = webApp.dataLayerId !== undefined ? (node) => datalayer_integration_1.hydrateFromDataLayer(node, loader_1.extractObject(isoConfig, types_1.default.INFRASTRUCTURE_TYPE_COMPONENT, webApp.dataLayerId)) : (node) => { //console.log("this is the dummy data layer hydration"); return node; }; react_dom_1.hydrate(fHydrate(routed_app_1.createClientApp(webApp.routes, webApp.redirects, basename, webApp.listenOnBrowserHistory, require('infrastructure-components').getAuthCallback(isoConfig, webApp.authenticationId), preloadedState, preloadedFiles)), document.getElementById('root')); }; // this module MUST NOT export anything else. Because it would also load the default, which would be executed right away exports.default = createClientWebApp(); //# sourceMappingURL=client.js.map