Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the route options to the "routeObj" emited by the "router:bind" sails event #3326

Merged
merged 1 commit into from
Nov 20, 2015

Conversation

AlexisNo
Copy link
Contributor

A small modification to include the route options in the object emitted by the router:bind event.

That would be very useful for hooks. It could replace (or maybe be used to implement?) the sails.getRoutes() method proposed in the comments of PR-2659.

Besides being useful for routing and debugging hooks, it could be used to generate api documentations like Swagger, Raml or API Blueprint. For example, the sails-swagger hook is kind of reverse engineering the content of sails.router._privateRouter.routes to find models associated to routes. The task is even more awkward if you have to retrieve blueprint prefixes or manage the blueprints.pluralize configuration.

Having the possibility to read the route's options when listening at the router:bind event would make this task trivial. Example of value retrieved for a rest blueprint route:

{ path: '/pet/:id',
  target: [Function: routeTargetFnWrapper],
  verb: 'post',
  options: 
   { associations: [],
     actions: true,
     index: true,
     shortcuts: true,
     rest: true,
     prefix: '',
     restPrefix: '',
     pluralize: false,
     populate: true,
     autoWatch: true,
     model: 'pet',
     action: 'update',
     controller: 'pet',
     detectedVerb: { verb: '', original: '/pet/:id', path: '/pet/:id' },
     skipRegex: [] },
  originalFn: { [Function: updateOneRecord] _middlewareType: 'BLUEPRINT: updateOneRecord' }
}

Finally, options is already available in the object emitted by the router:route event. I think it would make sense to make it available when router:bind is fired too.

@moisesrodriguez
Copy link

👍

@danieltorrer
Copy link

awesome job, cant wait to use it. 👍

tjwebb added a commit that referenced this pull request Nov 20, 2015
Add the route options to the "routeObj" emited by the "router:bind" sails event
@tjwebb tjwebb merged commit 9714c47 into balderdashy:master Nov 20, 2015
@tjwebb
Copy link
Contributor

tjwebb commented Nov 20, 2015

Cool! If you want to help out with sails-swagger, any help is appreciated :)

@weyert
Copy link

weyert commented Nov 21, 2015

This looks interesting. Looks like I could make a hook to allow assigning a name to a route then attempt to generate a url from a named route. article_more_info (/v1/articles/:id/more_info) -> article_more_info(1) -> /v1/articles/1/more_info. This would then allow to inject url in model instances so you have resource uri's

@mikermcneil
Copy link
Member

re: api for reverse routing in particular - see #3402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants