Giter VIP home page Giter VIP logo

Comments (6)

The-EDev avatar The-EDev commented on May 31, 2024

I'm still not sure what removing routes means, does it mean removing them in real-time while the server is running? or something completely different.

from crow.

mrozigor avatar mrozigor commented on May 31, 2024

I think that issue was to dynamically remove routes in response to some user action or application state, during runtime.

from crow.

The-EDev avatar The-EDev commented on May 31, 2024

Well such a thing could easily be done with a middleware, you just have a list of removed routes, a function to remove a route (by adding it to the list), and have your before_handle return a 404 if the path matches a removed route, we can probably also use the existing route matching system, or black_magic to get the type of any variable in the user (things like /endpoint/<int>) in the URL.

Though I don't recall any web API (or webserver) that I know of dynamically removing an endpoint based on some action. But it's 2020 anything can happen :D

from crow.

The-EDev avatar The-EDev commented on May 31, 2024

Crow stores all the rules in 2 data structures, a vector of rule object pointers, and a Trie for searching

The way a Trie works for crow (definitely look up Trie data structures before reading this) is it stores each character of a rule's URL in a tree node, with only the last character having a variable called a rule_index, the find algorithm is meant to go through a given URL char by char until the last node is reached, then the rule index from that node will be the one to correspond to where in the vector the rule (and its handler) is.

Crow's Trie does not have a "delete rule" method, Implementing such a method would require the following:

  • Finding the rule in the trie.
  • checking if the last node has any children.
  • if it does, then only remove the rule_index.
  • otherwise delete nodes one by one (from the leaf node up) until the first node with a rule_index or the haed node is reached.

Update: The new Trie system has actually not invalidated the above process at all (even with optimization), it actually reinforced it. Though I'm still unsure whether this would be a necessary feature..

from crow.

The-EDev avatar The-EDev commented on May 31, 2024

closing this issue since I don't believe this feature should be added to Crow, @mrozigor please let me know if you disagree.

from crow.

nuno636 avatar nuno636 commented on May 31, 2024

The idea of removing a route makes perfect sense to me. We can add a blueprint at runtime, loading it from an external shared library, so we should be able to remove it too.
I just tried exactly this: creating a .dll with just a blueprint, load the .dll at runtime and register the blueprint. It works perfectly. Now, what if I want to unload this dll? With the dll blueprint registered I can't unload the library without a crash.
I agree, there should be a way to deregister a route.

  • EDIT -
    I just tried to add a deregisterBlueprint(Blueprint bp) function and it works fine: it just removes the blueprint from std::vector<Blueprint> app::router_.blueprints(). Of course, there should be checks to see if the route/BP is being used before deleting it and such, mine is just a quick mockup to see if this is what I'm looking for.
    Now I'm able to load the blueprints at runtime from an external library (a DLL in my case), use it and then remove it and unload the DLL.
    This allows me to have a small central app (the server itself) and to dynamically add and remove routes via plugins without ever stopping the server. The main app would crash if the blueprint was still in use at the moment of unloading the DLL.

It's quite handy, I think this feature makes perfect sense.

from crow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.