feat: adding configuration environtment
This commit is contained in:
parent
a6639dc206
commit
b9f7f3fd60
|
@ -0,0 +1,3 @@
|
||||||
|
MONGO_URI=mongodb://localhost:27017/quiz_app
|
||||||
|
FLASK_ENV=development
|
||||||
|
DEBUG=True
|
|
@ -1,2 +1,3 @@
|
||||||
|
from .default import default_blueprint
|
||||||
from .auth import auth_blueprint
|
from .auth import auth_blueprint
|
||||||
from .user import user_blueprint
|
from .user import user_blueprint
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,9 @@
|
||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
|
default_blueprint = Blueprint("default", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@default_blueprint.route("/")
|
||||||
|
def home():
|
||||||
|
return "Welcome to the Home Page!"
|
|
@ -0,0 +1 @@
|
||||||
|
from .config import Config
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,18 @@
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv() # Load environment variables from .env
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
MONGO_URI = os.getenv(
|
||||||
|
"MONGO_URI", "mongodb://localhost:27017/quiz_app"
|
||||||
|
) # Default value if not set
|
||||||
|
|
||||||
|
FLASK_ENV = os.getenv("FLASK_ENV", "development") # Default to development
|
||||||
|
|
||||||
|
DEBUG = os.getenv("DEBUG", "True").lower() in [
|
||||||
|
"true",
|
||||||
|
"1",
|
||||||
|
"t",
|
||||||
|
] # Convert string to boolean
|
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
from .db import init_db
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,11 @@
|
||||||
|
from flask_pymongo import PyMongo
|
||||||
|
from flask import Flask
|
||||||
|
from configs import Config
|
||||||
|
|
||||||
|
mongo = PyMongo()
|
||||||
|
|
||||||
|
|
||||||
|
def init_db(app: Flask):
|
||||||
|
app.config["MONGO_URI"] = Config.MONGO_URI
|
||||||
|
print(Config.MONGO_URI)
|
||||||
|
mongo.init_app(app)
|
15
app/main.py
15
app/main.py
|
@ -1,10 +1,21 @@
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from blueprints import auth_blueprint, user_blueprint
|
from blueprints import auth_blueprint, user_blueprint, default_blueprint
|
||||||
|
from database import init_db
|
||||||
|
from configs import Config # Import the config class
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Apply configurations environtment
|
||||||
|
app.config["FLASK_ENV"] = Config.FLASK_ENV
|
||||||
|
app.config["DEBUG"] = Config.DEBUG
|
||||||
|
|
||||||
|
# Initialize database
|
||||||
|
init_db(app)
|
||||||
|
|
||||||
|
# Register blueprints
|
||||||
|
app.register_blueprint(default_blueprint)
|
||||||
app.register_blueprint(auth_blueprint, url_prefix="/api")
|
app.register_blueprint(auth_blueprint, url_prefix="/api")
|
||||||
app.register_blueprint(user_blueprint, url_prefix="/api")
|
app.register_blueprint(user_blueprint, url_prefix="/api")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=Config.DEBUG)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -2,3 +2,4 @@ Flask==3.0.3
|
||||||
numpy==2.1.2
|
numpy==2.1.2
|
||||||
pymongo
|
pymongo
|
||||||
Flask-PyMongo
|
Flask-PyMongo
|
||||||
|
python-dotenv
|
||||||
|
|
Loading…
Reference in New Issue