Skip to content

Commit

Permalink
fix: do not allow public route definitions to set private params (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba authored Aug 2, 2016
1 parent 278ab5d commit 1172d56
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 0 additions & 8 deletions src/packages/router/define/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// @flow
import route from './utils/define-route';
import resource from './utils/define-resource';

export { default as route } from './utils/define-route';
export { default as resource } from './utils/define-resource';

export default {
route,
resource
};
11 changes: 10 additions & 1 deletion src/packages/router/define/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// @flow
import type Router from '../index';
import type Controller from '../../controller';
import type { Route$opts } from '../../route';

export type options = Route$opts & { router: Router };
export type Router$route = Route$opts & {
router: Router;
};

export type Router$resource = {
path: string;
router: Router;
controllers: Map<string, Controller>;
};
9 changes: 3 additions & 6 deletions src/packages/router/define/utils/define-resource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import defineRoute from './define-route';
import type { options } from '../interfaces';

import type { Router$resource } from '../interfaces';

/**
* @private
Expand All @@ -9,11 +10,7 @@ export default function defineResource({
path,
router,
controllers
}: {
path: options.path;
router: options.router;
controllers: options.controllers;
}): void {
}: Router$resource) {
defineRoute({
path,
router,
Expand Down
4 changes: 2 additions & 2 deletions src/packages/router/define/utils/define-route.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import Route from '../../../route';

import type { options } from '../interfaces';
import type { Router$route } from '../interfaces';

/**
* @private
*/
export default function defineRoute({ router, ...opts }: options): void {
export default function defineRoute({ router, ...opts }: Router$route) {
const route = new Route(opts);

router.set(`${route.method}:/${route.staticPath}`, route);
Expand Down
7 changes: 4 additions & 3 deletions src/packages/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ID_PATTERN } from '../route';

import { FreezeableMap } from '../freezeable';

import define from './define';
import * as define from './define';

import type { Request } from '../server';
import type { Router$opts } from './interfaces';
Expand All @@ -17,9 +17,10 @@ class Router extends FreezeableMap<string, Route> {
super();

Reflect.apply(routes, {
route: (path: string, opts: Route$opts) => define.route({
...opts,
route: (path: string, { method, action }: Route$opts) => define.route({
path,
method,
action,
controllers,
router: this
}),
Expand Down
5 changes: 3 additions & 2 deletions src/packages/router/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type Controller from '../controller';

export type Router$opts = {
routes: () => void,
controllers: Map<string, Controller>
controllers: Map<string, Controller>;

routes(): void;
};

0 comments on commit 1172d56

Please sign in to comment.