Comments (6)
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.
I think that issue was to dynamically remove routes in response to some user action or application state, during runtime.
from crow.
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.
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.
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.
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)
- boost-container:x64-windows failed with: BUILD_FAILED
- Memory leak when websocket sends data HOT 6
- Unable to find `get_body_params` HOT 1
- TIME OUT
- The Decimal Digit Problem of Double Type in wvalue
- Server crash upon terminating websocket client HOT 1
- The latest release is out of date? HOT 1
- struct crow::request has no member named get_body_params HOT 2
- Dumping double value to string can cause a precision loss
- Crow continues to LISTEN on the port after calling `stop` method HOT 1
- Buggy Blueprint Catchall behavior HOT 1
- Error: At global scope, expected identifier before numeric constant while include crow HOT 1
- Use middleware in blueprint is not support in handle_full unit test
- Cannot enable local middleware for specific hanlder while using app.route_dynamic.
- Segmentation fault in websocket.h
- Support wss? I only found examples for ws
- Crow does not reply to browser preflight messages correctly when using CORs middleware HOT 1
- Update Crow to the Latest Version in VCPKG HOT 1
- How to read values from crow::json::wvalue object? HOT 4
- mutiple crow server with same port in windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crow.