Skip to content

Commit

Permalink
Sander/add config to handled route (#206)
Browse files Browse the repository at this point in the history
* fix(behaviour of postrender array): makes sure the postreder array is passed correctly

<ake sure it doesn't throw out the defaults if no specific route postRenderes are configured. Also
pass the config into the handledRoute

* feat(index.ts): export httpGetJson helper from scully
  • Loading branch information
SanderElias authored and jorgeucano committed Jan 21, 2020
1 parent 5d7aa47 commit 9f0a9c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions scully/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {registerPlugin, configValidator} from './pluginManagement/pluginRepository';
import {configValidator, registerPlugin} from './pluginManagement/pluginRepository';
import './pluginManagement/systemPlugins';
import {HandledRoute} from './routerPlugins/addOptionalRoutesPlugin';
import {updateScullyConfig} from './utils/config';
import {httpGetJson} from './utils/httpGetJson';
import {RouteTypes, ScullyConfig} from './utils/interfacesandenums';
import {routeSplit} from './utils/routeSplit';
import {replaceFirstRouteParamWithVal} from './utils/replaceFirstRouteParamWithVal';
import {routeSplit} from './utils/routeSplit';
import {startScully} from './utils/startup';

export {
Expand All @@ -17,4 +18,5 @@ export {
routeSplit,
replaceFirstRouteParamWithVal,
configValidator,
httpGetJson,
};
12 changes: 7 additions & 5 deletions scully/routerPlugins/addOptionalRoutesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {logError, yellow, logWarn} from '../utils/log';
export const addOptionalRoutes = async (routeList = [] as string[]): Promise<HandledRoute[]> => {
const routesToGenerate = await routeList.reduce(async (result: Promise<HandledRoute[]>, cur: string) => {
const x = await result;
if (scullyConfig.routes[cur]) {
const postRenderers: string[] = Array.isArray(scullyConfig.routes[cur].postRenderers)
? scullyConfig.routes[cur].postRenderers
: [];
const config = scullyConfig.routes[cur];
if (config) {
const postRenderers: string[] = Array.isArray(config.postRenderers) ? config.postRenderers : undefined;
/** adding in the postrenderes. Note that the plugin might choose to overwrite the ones that come from the config */
const r = (await routePluginHandler(cur)).map(r => ({postRenderers, ...r}));
const r = (await routePluginHandler(cur)).map(row =>
postRenderers ? {postRenderers, ...row, config} : {...row, config}
);
x.push(...r);
} else if (cur.includes('/:')) {
logWarn(`No configuration for route "${yellow(cur)}" found. Skipping`);
Expand All @@ -27,6 +28,7 @@ export const addOptionalRoutes = async (routeList = [] as string[]): Promise<Han
export interface HandledRoute {
route: string;
type: RouteTypes;
config?: {[key: string]: any};
postRenderers?: string[];
templateFile?: string;
data?: RouteData;
Expand Down

0 comments on commit 9f0a9c2

Please sign in to comment.