1

I want to dynamically during runtime of sailsjs add/remove routes. what is the way?

I found a function to add route:

sails.router.bind(path, target);

and it will work but when I ant to unbind it, it does not work.

sails.router.unbind(???);
Anthon
  • 69,918
  • 32
  • 186
  • 246

1 Answers1

2

its a route object includes method and path

Source code as below

Router.prototype.unbind = function(route) {

  var sails = this.sails;

  // Inform attached servers that route should be unbound
  sails.emit('router:unbind', route);

  // Remove route in internal router
  var newRoutes = [];
  _.each(this._privateRouter.routes[route.method], function(expressRoute) {
    if (expressRoute.path != route.path) {
      newRoutes.push(expressRoute);
    }
  });
  this._privateRouter.routes[route.method] = newRoutes;

};
Ryan Wu
  • 5,963
  • 2
  • 36
  • 47