node.js - sailsjs routes for both generated and defined -


I am trying to get the full list of API methods available from my service. This mainly indicates that we are exposing the API call through all the controllers I know that I can self-surrender to sails.config.routes object to get the list of defined routes. Although there is not an easy way to get a list of blueprint routes that is automatically generated for you. Now one idea is that I can adopt a specific pattern with 3 different types of blueprint (action, comfort, and shortcut). It is a bad idea for this simple fact that this structure is in its infancy and to change things, I trust a method to achieve this list on the basis of actually defined, and if it does change So my code should focus on it automatically.

So I opened in Pal and sealed under cover is dependent on expressing all the routing.

On lines 35 I initialize.js lines found this bit of code.

  // Express Server var app = sails.hooks.http.app = express (); I then discovered how others use API Express. So I was brought to different pages and both were very useful, I also realized that Paul is using the Express version 3.4.3 and not 4. It is disappointing that Express 4 has been out of about a year so far. Okay, we get the problem problem. Everything is stored in sails.hooks.http.app.routes, although there is a lot of duplication in the routes and it is like messy for the output by itself. Here I was able to output it well.  
  // Where all the paths are stored i var routes = sails.hooks.http.app.routes; Var API = {}; Var Output = []; (For various methods in the routes) {for (index in the route [method]) {var path = route [method] [index]; For (opt in var route) {if (API [method] === undefined) {API [method] = {}; } If (API [method] [path path] == undefined and path path! == "/ *" & path path! == "/") {API [method] [route.svg] = Route.param; } //output.push (++++ + + +)) "+ Opt +" & amp; Nbsp; & Amp; Nbsp; & Amp; Nbsp; & Amp; Nbsp; + Route [opt] + "
"); }}} For (method in API) {{path in API [method]) {output.push (method + "& amp; nbsp; amp; amp; nbsp;" + route); }} Res.send (output.join ("& lt; br / & gt;"));

I hope that it will be helpful for someone else to achieve similar effect. I think it is very sad that such data has not been exposed to a well. We have hidden, and we have to hunt through the code of God. My goal would be to call a service that would disclose an angled service that will consume my API and display all available methods only

Enjoy!

This service is making it easy to consume and remove any type of mapping requirement.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -