diff --git a/code/backend/backend.iml b/code/backend/backend.iml index 65017c1..e6b7d9d 100644 --- a/code/backend/backend.iml +++ b/code/backend/backend.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/code/backend/nest_backend/__main__.py b/code/backend/nest_backend/__main__.py index a9799d1..9e73ebc 100644 --- a/code/backend/nest_backend/__main__.py +++ b/code/backend/nest_backend/__main__.py @@ -1,7 +1,6 @@ """ This is the runner for the server. """ -from flask import Flask import os import werkzeug.middleware.proxy_fix from .routes import * @@ -10,27 +9,11 @@ import psycopg2 from .gestione import * from flask_cors import CORS from flask_jwt_extended import * +from .app import app -app = Flask(__name__) -if os.getenv('COOKIE_SECRET'): - app.secret_key = os.getenv('COOKIE_SECRET') -else: - app.secret_key = "testing" -if os.getenv("JWT_SECRET_KEY"): - app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY") -else: - app.config["JWT_SECRET_KEY"] = "testing" +Base.init_app(app=app) reverse_proxy_app = werkzeug.middleware.proxy_fix.ProxyFix(app=app, x_for=1, x_proto=0, x_host=1, x_port=0, x_prefix=0) -if os.getenv("DATABASE_URI"): - app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URI') -else: - app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost:5432/PdSDev' -Base.app = app -Base.init_app(app) -jwt = JWTManager(app) -cors = CORS(app) -app.config['CORS_HEADERS'] = 'Content-Type' # Routes setup app.add_url_rule("/doa", view_func=page_doa, methods=["GET", "POST"]) @@ -43,11 +26,12 @@ app.add_url_rule("/api/repository/edit", view_func=page_repository_edit, methods app.add_url_rule("/api/repository/add_condition", view_func=page_repository_add_condition, methods=["POST"]) if __name__ == "__main__": - Base.create_all() - if not User.query.filter_by(isAdmin=True).all(): - Base.session.add(User(email="admin@admin.com", password=gen_password("password"), username="admin", isAdmin=True)) - Base.session.commit() - debug = True - if os.getenv("DISABLE_DEBUG"): - debug = False + with app.app_context(): + Base.create_all(app=app) + if not User.query.filter_by(isAdmin=True).all(): + Base.session.add(User(email="admin@admin.com", password=gen_password("password"), username="admin", isAdmin=True)) + Base.session.commit() + debug = True + if os.getenv("DISABLE_DEBUG"): + debug = False app.run(debug=debug) diff --git a/code/backend/nest_backend/app.py b/code/backend/nest_backend/app.py new file mode 100644 index 0000000..4b4ec08 --- /dev/null +++ b/code/backend/nest_backend/app.py @@ -0,0 +1,17 @@ +from flask import Flask +import os + + +app = Flask(__name__) +if os.getenv('COOKIE_SECRET'): + app.secret_key = os.getenv('COOKIE_SECRET') +else: + app.secret_key = "testing" +if os.getenv("JWT_SECRET_KEY"): + app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY") +else: + app.config["JWT_SECRET_KEY"] = "testing" +if os.getenv("DATABASE_URI"): + app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URI') +else: + app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost:5432/PdSDev' \ No newline at end of file diff --git a/code/backend/nest_backend/tweet-explorer/__main__.py b/code/backend/nest_backend/tweet-explorer/__main__.py new file mode 100644 index 0000000..5dd4e9d --- /dev/null +++ b/code/backend/nest_backend/tweet-explorer/__main__.py @@ -0,0 +1,14 @@ +from nest_backend.app import app +from nest_backend.database import * + +Base.init_app(app=app) + + +def start_exploring(): + pass # Codice qui + + +if __name__ == "__main__": + with app.app_context(): + Base.create_all(app=app) + start_exploring()