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:
parent
90af13e2a9
commit
76bac0833e
4 changed files with 42 additions and 27 deletions
|
@ -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>
|
|
@ -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,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"])
|
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():
|
||||||
if not User.query.filter_by(isAdmin=True).all():
|
Base.create_all(app=app)
|
||||||
Base.session.add(User(email="admin@admin.com", password=gen_password("password"), username="admin", isAdmin=True))
|
if not User.query.filter_by(isAdmin=True).all():
|
||||||
Base.session.commit()
|
Base.session.add(User(email="admin@admin.com", password=gen_password("password"), username="admin", isAdmin=True))
|
||||||
debug = True
|
Base.session.commit()
|
||||||
if os.getenv("DISABLE_DEBUG"):
|
debug = True
|
||||||
debug = False
|
if os.getenv("DISABLE_DEBUG"):
|
||||||
|
debug = False
|
||||||
app.run(debug=debug)
|
app.run(debug=debug)
|
||||||
|
|
17
code/backend/nest_backend/app.py
Normal file
17
code/backend/nest_backend/app.py
Normal 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'
|
14
code/backend/nest_backend/tweet-explorer/__main__.py
Normal file
14
code/backend/nest_backend/tweet-explorer/__main__.py
Normal 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()
|
Loading…
Reference in a new issue