Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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