0

I have a JSON config file which specifies API end-points. I read it on app load and iterate through its keys, like this

server[type](config.path, function (req, res, next) {

});

Now, I am looking for a way to remove that route from server. I mean delete the API I just created. Is there any way by which it can be done? I checked the docs but couldn't find anything related to this.

I tried removing keys in server.routes. But it creates new keys with different name and I am not sure why it creates. for example if I delete a route getusers from server.routes, a new key is created like server.routes.getusers234234 (some random number appended).

Salman
  • 9,299
  • 6
  • 40
  • 73
  • Why would you do that? I've never had a project that required me to change routes on the fly. Once, I read a Netflix blog post where they tried to do something similar and they introduced a memory leak... (So, this might not be the best way/idea to do this) – Max Apr 10 '15 at 22:05
  • I see. But just to understand how this works. I mean If I can create routes on the fly, why can't I remove/change them! I haven't looked at the source yet, but routes seems nothing but a map of `type+api` so removing them, or changing them should be easy thing to do. – Salman Apr 11 '15 at 05:02
  • Can you give me an example use case? – Max Apr 11 '15 at 08:49
  • Okay, what I am trying to implement is a config based API which can be changed without restarting the application. I would call a function on specific event, which would delete previous routes and add new ones. each route would act as per settings in that config file I mentioned. – Salman Apr 12 '15 at 11:25
  • What Max mentioned about Netflix from memory is not entirely correct. They moved away from Express to Restify as Express was leaking when they where trying to remove routes. – Mike May 07 '16 at 08:38

1 Answers1

1

The best way to remove a route in Restify would, I believe, be to scan server.routes.mounts for any routes you want to remove and then pass each of those route objects to server.rm.

Mike
  • 1,648
  • 1
  • 16
  • 15