diff --git a/app/config.py b/app/config.py index 1974439..a4c46ff 100644 --- a/app/config.py +++ b/app/config.py @@ -11,5 +11,5 @@ if path.exists((cfg_pth := path.join(config_path, "../config.cfg"))): config.read(cfg_pth) settings = { - "mongodb_url": config.get("DB","MONGODB_URL") + "mongodb_uri": config.get("DB","MONGODB_URI") } \ No newline at end of file diff --git a/app/db.py b/app/db.py new file mode 100644 index 0000000..cef6a01 --- /dev/null +++ b/app/db.py @@ -0,0 +1,19 @@ +from flask import current_app, g +from werkzeug.local import LocalProxy +from flask_pymongo import PyMongo + + +def get_db(): + """ + Configuration method to return db instance + """ + db = getattr(g, "_database", None) + + if db is None: + db = g._database = PyMongo(current_app).db + + return db + + +# Use LocalProxy to read the global db instance with just `db` +db = LocalProxy(get_db) diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..c274302 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,17 @@ +from flask import current_app as app +from flask import request +from .db import db + + +@app.route("/detail", methods=["GET"]) +def detail(): + if "ico" not in request.args: + return "missing ico" + else: + ico = request.args["ico"] + return f"ICO je {ico}" + + +@app.route("/list", methods=["GET"]) +def list_data(): + return "list" diff --git a/config_base.cfg b/config_base.cfg index 21daf43..c4a89ec 100644 --- a/config_base.cfg +++ b/config_base.cfg @@ -1,2 +1,2 @@ [DB] -MONGODB_URL = "mongodb://localhost:27017" \ No newline at end of file +MONGODB_URI = "mongodb://localhost:27017/softone" \ No newline at end of file diff --git a/flaskapp.py b/flaskapp.py index e69de29..ddda1a3 100644 --- a/flaskapp.py +++ b/flaskapp.py @@ -0,0 +1,20 @@ +from flask import Flask +from app.config import settings + + +def create_app(): + + flaskapp = Flask(__name__) + + with flaskapp.app_context(): + from app import routes + + return flaskapp + + +if __name__ == "__main__": + app = create_app() + app.config["Debug"] = True + app.config["MONGO_URI"] = settings["mongodb_uri"] + + app.run() diff --git a/requirements.txt b/requirements.txt index e69de29..c7138a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask~=2.3.3 +Flask-PyMongo~=2.3.0 \ No newline at end of file