Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scripts: Array,
enableServiceWorker: boolean,
cssLinks: ?(Array | (MWPState => Array)),
}) => {
const {
routes,
reducer,
middleware,
scripts,
cssLinks,
enableServiceWorker,
} = renderConfig;
// set up a Promise that emits the resolved routes - this single Promise will
// be reused for all subsequent requests, so we're not resolving the routes repeatedly
// hooray performance
const routesPromise = resolveAllRoutes(routes);
return (request: HapiRequest, h: HapiResponseToolkit): Promise => {
if (!scripts.length) {
throw new Error('No client script assets specified');
}
const appContext = getAppContext(request, enableServiceWorker);
// create the store with populated `config`
const initializeStore = resolvedRoutes => {
const createStore = getServerCreateStore(
getFindMatches(resolvedRoutes, appContext.basename),
middleware || [],
request
);
const initialState = { config: appContext };
return Promise.resolve(createStore(reducer, initialState));