1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-30 00:14:19 +00:00
pds-2021-g2-nest/code/backend/nest_backend/__main__.py

42 lines
1.6 KiB
Python
Raw Normal View History

"""
This is the runner for the server.
"""
2021-04-19 14:14:51 +00:00
import os
import werkzeug.middleware.proxy_fix
2021-04-19 14:23:50 +00:00
from .routes import *
2021-04-22 14:54:27 +00:00
from .database import Base, tables
import psycopg2
from .gestione import *
from flask_cors import CORS
from flask_jwt_extended import *
from .app import app
2021-04-19 14:14:51 +00:00
Base.init_app(app=app)
2021-04-27 20:48:43 +00:00
jwt = JWTManager(app)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
2021-04-19 14:14:51 +00:00
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)
# Routes setup
2021-04-22 14:54:27 +00:00
app.add_url_rule("/doa", view_func=page_doa, methods=["GET", "POST"])
app.add_url_rule("/api/login", view_func=page_login, methods=["POST"])
app.add_url_rule("/api/user/create", view_func=page_user_create, methods=["POST"])
app.add_url_rule("/api/user/remove", view_func=page_user_delete, methods=["POST"])
app.add_url_rule("/api/repository/list", view_func=page_repository_list, methods=["GET"])
app.add_url_rule("/api/repository/create", view_func=page_repository_create, methods=["POST"])
app.add_url_rule("/api/repository/edit", view_func=page_repository_edit, methods=["PUT"])
app.add_url_rule("/api/repository/add_condition", view_func=page_repository_add_condition, methods=["POST"])
2021-04-19 14:14:51 +00:00
if __name__ == "__main__":
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)