How to use the mwp-router/lib/util.resolveAllRoutes function in mwp-router

To help you get started, we’ve selected a few mwp-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meetup / meetup-web-platform / packages / mwp-core / src / renderers / server-render.jsx View on Github external
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));