Skip to content

Commit

Permalink
feat: expose controller and action in public request api (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba authored Oct 15, 2016
1 parent e289ffc commit 54db513
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/packages/server/request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ export function createRequest(req: any, {
method: headers.get('x-http-method-override') || req.method
});

Reflect.set(req, 'route', router.match(req));
const route = router.match(req);

if (route) {
Object.assign(req, {
route,
action: route.action,
controller: route.controller
});
}

return req;
}
Expand Down
3 changes: 3 additions & 0 deletions src/packages/server/request/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import type Logger from '../../logger';
import type Router, { Route } from '../../router';
import type Controller from '../../controller';

export type Request$opts = {
logger: Logger;
Expand Down Expand Up @@ -61,6 +62,8 @@ declare export class Request extends stream$Readable {
params: Request$params;
defaultParams: Request$params;
route: Route;
action: string;
controller: Controller;
url: Request$url;

connection: {
Expand Down

0 comments on commit 54db513

Please sign in to comment.