From 9e2cb802005887cbd2480ef02a48603e1d174ca3 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 5 Nov 2020 11:55:38 +0100 Subject: fix: default imported modules --- frest/app.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ frest/database.py | 4 ++++ frest/mail.py | 11 +++++++++++ frest/wsgi.py | 4 ++++ 4 files changed, 76 insertions(+) create mode 100644 frest/app.py create mode 100644 frest/database.py create mode 100644 frest/mail.py create mode 100644 frest/wsgi.py diff --git a/frest/app.py b/frest/app.py new file mode 100644 index 0000000..ca46277 --- /dev/null +++ b/frest/app.py @@ -0,0 +1,57 @@ +from flask import Flask +from auth.routes import api as api_users +from flask import make_response, jsonify +from database import db +from database import config as db_config +from mail import mail +from mail import config as mail_config +from flask_sqlalchemy import SQLAlchemy +from utils import http_call +from flask_cors import CORS +import os + +app = Flask(__name__) +app.config["SQLALCHEMY_DATABASE_URI"] = db_config["DATABASE_URI"] +app.config["DEBUG"] = os.getenv("FREST_DEBUG", True) +app.config["CORS_HEADERS"] = "Content-Type" +app.config["MAIL_SERVER"] = mail_config["SERVER"] +app.config["MAIL_PORT"] = mail_config["PORT"] +app.config["MAIL_USE_TLS"] = mail_config["USE_TLS"] +app.config["MAIL_USERNAME"] = mail_config["USERNAME"] +app.config["MAIL_DEFAULT_SENDER"] = mail_config["DEFAULT_SENDER"] +app.config["MAIL_PASSWORD"] = mail_config["PASSWORD"] + +cors = CORS(app, resources={r"/.*": {"origins": "*"}}) +db.app = app +db.init_app(app) +mail.init_app(app) +app.register_blueprint(api_users) + + +@app.errorhandler(404) +def not_found(error): + return http_call("Not found", 404) + + +@app.errorhandler(400) +def bad_request(error): + return http_call("Bad request", 400) + + +@app.errorhandler(405) +def method_not_allowed(error): + return http_call("Method not allowed", 405) + + +@app.errorhandler(403) +def forbiddend(error): + return http_call("Forbidden", 403) + + +@app.errorhandler(500) +def internal(error): + return http_call("Internal error", 500) + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/frest/database.py b/frest/database.py new file mode 100644 index 0000000..176cd52 --- /dev/null +++ b/frest/database.py @@ -0,0 +1,4 @@ +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() +config = {"DATABASE_URI": "sqlite:///database.db"} diff --git a/frest/mail.py b/frest/mail.py new file mode 100644 index 0000000..e553525 --- /dev/null +++ b/frest/mail.py @@ -0,0 +1,11 @@ +from flask_mail import Mail + +mail = Mail() +config = { + "SERVER": "", + "PORT": 587, + "USE_TLS": True, + "USERNAME": "", + "DEFAULT_SENDER": "", + "PASSWORD": "", +} diff --git a/frest/wsgi.py b/frest/wsgi.py new file mode 100644 index 0000000..6026b0f --- /dev/null +++ b/frest/wsgi.py @@ -0,0 +1,4 @@ +from app import app + +if __name__ == "__main__": + app.run() -- cgit v1.2.3-18-g5258