1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 14:34:19 +00:00

App module + Explorer module

Now the app is inside its own module and can be used by the bot.
This commit is contained in:
Lorenzo Balugani 2021-04-27 16:34:55 +02:00
parent 90af13e2a9
commit 76bac0833e
4 changed files with 42 additions and 27 deletions

View file

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/nest_backend" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/nest_backend" isTestSource="false" />
</content> </content>
<orderEntry type="jdk" jdkName="Poetry (backend)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Poetry (g2-progetto) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View file

@ -1,7 +1,6 @@
""" """
This is the runner for the server. This is the runner for the server.
""" """
from flask import Flask
import os import os
import werkzeug.middleware.proxy_fix import werkzeug.middleware.proxy_fix
from .routes import * from .routes import *
@ -10,27 +9,11 @@ import psycopg2
from .gestione import * from .gestione import *
from flask_cors import CORS from flask_cors import CORS
from flask_jwt_extended import * from flask_jwt_extended import *
from .app import app
app = Flask(__name__) Base.init_app(app=app)
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"
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) 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 # Routes setup
app.add_url_rule("/doa", view_func=page_doa, methods=["GET", "POST"]) app.add_url_rule("/doa", view_func=page_doa, methods=["GET", "POST"])
@ -43,7 +26,8 @@ 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"]) app.add_url_rule("/api/repository/add_condition", view_func=page_repository_add_condition, methods=["POST"])
if __name__ == "__main__": if __name__ == "__main__":
Base.create_all() with app.app_context():
Base.create_all(app=app)
if not User.query.filter_by(isAdmin=True).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.add(User(email="admin@admin.com", password=gen_password("password"), username="admin", isAdmin=True))
Base.session.commit() Base.session.commit()

View file

@ -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'

View file

@ -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()