diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-22 13:43:33 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-22 13:43:33 +0100 |
commit | c02dc3a493cf66f5c4a6ccd2a1155c3f8c2e37ef (patch) | |
tree | 5e408e28cdf81e67bc1f2894d6df403d8b20671e /api/dynamic_import.py | |
parent | 32aaaf92f2c06214abdc93e3cede07e067df6b88 (diff) |
added dynamic api routing
Diffstat (limited to 'api/dynamic_import.py')
-rw-r--r-- | api/dynamic_import.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/api/dynamic_import.py b/api/dynamic_import.py new file mode 100644 index 0000000..f7945f9 --- /dev/null +++ b/api/dynamic_import.py @@ -0,0 +1,20 @@ +from app import app +import importlib +import os +import log +import glob + +files = glob.glob(os.path.dirname(__file__) + "/**/*.py", recursive=True) +files.remove(__file__) +files = [str(filename) + .replace(os.path.dirname(__file__) + "/", '') + .replace("/", ".") + .replace(".py", '') + for filename in files] + +for file in files: + mod = importlib.import_module(file) + if not hasattr(mod, "dynamic_route"): continue + app.register_blueprint(mod.dynamic_route[1], url_prefix=mod.dynamic_route[0]) + log.info(f"dynamically routing {mod.dynamic_route[0]}{mod.dynamic_route[1].import_name}") + |