Skip to content

Commit 9f0a9c2

Browse files
SanderEliasjorgeucano
authored andcommitted
Sander/add config to handled route (#206)
* 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
1 parent 5d7aa47 commit 9f0a9c2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

scully/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import {registerPlugin, configValidator} from './pluginManagement/pluginRepository';
1+
import {configValidator, registerPlugin} from './pluginManagement/pluginRepository';
22
import './pluginManagement/systemPlugins';
33
import {HandledRoute} from './routerPlugins/addOptionalRoutesPlugin';
44
import {updateScullyConfig} from './utils/config';
5+
import {httpGetJson} from './utils/httpGetJson';
56
import {RouteTypes, ScullyConfig} from './utils/interfacesandenums';
6-
import {routeSplit} from './utils/routeSplit';
77
import {replaceFirstRouteParamWithVal} from './utils/replaceFirstRouteParamWithVal';
8+
import {routeSplit} from './utils/routeSplit';
89
import {startScully} from './utils/startup';
910

1011
export {
@@ -17,4 +18,5 @@ export {
1718
routeSplit,
1819
replaceFirstRouteParamWithVal,
1920
configValidator,
21+
httpGetJson,
2022
};

scully/routerPlugins/addOptionalRoutesPlugin.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {logError, yellow, logWarn} from '../utils/log';
66
export const addOptionalRoutes = async (routeList = [] as string[]): Promise<HandledRoute[]> => {
77
const routesToGenerate = await routeList.reduce(async (result: Promise<HandledRoute[]>, cur: string) => {
88
const x = await result;
9-
if (scullyConfig.routes[cur]) {
10-
const postRenderers: string[] = Array.isArray(scullyConfig.routes[cur].postRenderers)
11-
? scullyConfig.routes[cur].postRenderers
12-
: [];
9+
const config = scullyConfig.routes[cur];
10+
if (config) {
11+
const postRenderers: string[] = Array.isArray(config.postRenderers) ? config.postRenderers : undefined;
1312
/** adding in the postrenderes. Note that the plugin might choose to overwrite the ones that come from the config */
14-
const r = (await routePluginHandler(cur)).map(r => ({postRenderers, ...r}));
13+
const r = (await routePluginHandler(cur)).map(row =>
14+
postRenderers ? {postRenderers, ...row, config} : {...row, config}
15+
);
1516
x.push(...r);
1617
} else if (cur.includes('/:')) {
1718
logWarn(`No configuration for route "${yellow(cur)}" found. Skipping`);
@@ -27,6 +28,7 @@ export const addOptionalRoutes = async (routeList = [] as string[]): Promise<Han
2728
export interface HandledRoute {
2829
route: string;
2930
type: RouteTypes;
31+
config?: {[key: string]: any};
3032
postRenderers?: string[];
3133
templateFile?: string;
3234
data?: RouteData;

0 commit comments

Comments
 (0)