From 4efa24b09bdab889b3a5f84a5319c7c134084e62 Mon Sep 17 00:00:00 2001 From: sovanna Date: Wed, 15 Apr 2020 12:40:34 +0900 Subject: [PATCH] feat(issue22/server-flask): Refactors archi - uses package rfq with only one file - adds basic setup.py - remove package versionning inside requirements - lets flask version in setup.py (issue regarding setuptools) --- server/README.md | 0 server/app/__init__.py | 22 -------------- server/app/api/__init__.py | 7 ----- server/config.py | 18 ------------ server/main.py | 4 --- server/requirements.txt | 20 ++++++------- server/{app/api/routes.py => rfq/__init__.py} | 29 ++++++++++++++++--- server/setup.py | 14 +++++++++ 8 files changed, 49 insertions(+), 65 deletions(-) delete mode 100644 server/README.md delete mode 100644 server/app/__init__.py delete mode 100644 server/app/api/__init__.py delete mode 100644 server/config.py delete mode 100644 server/main.py rename server/{app/api/routes.py => rfq/__init__.py} (72%) create mode 100644 server/setup.py diff --git a/server/README.md b/server/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/server/app/__init__.py b/server/app/__init__.py deleted file mode 100644 index 109d167..0000000 --- a/server/app/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -from flask import Flask -from flask_mail import Mail -from werkzeug.middleware.proxy_fix import ProxyFix - -import config - - -mail = Mail() - - -def create_app(cfg=config): - app = Flask(__name__) - app.config.from_object(cfg) - app.wsgi_app = ProxyFix(app.wsgi_app) - - mail.init_app(app) - - from app.api import bp as bp_api - - app.register_blueprint(bp_api) - - return app diff --git a/server/app/api/__init__.py b/server/app/api/__init__.py deleted file mode 100644 index d01fe23..0000000 --- a/server/app/api/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import Blueprint - - -bp = Blueprint("api", __name__, url_prefix="/api") - - -from app.api import routes # nopep8 diff --git a/server/config.py b/server/config.py deleted file mode 100644 index db7a238..0000000 --- a/server/config.py +++ /dev/null @@ -1,18 +0,0 @@ -from dotenv import load_dotenv -from os import getenv - - -load_dotenv() - - -DEBUG = True if getenv('FLASK_DEBUG') == 'True' else False -SECRET_KEY = getenv('FLASK_SECRET_KEY') - -MAIL_SERVER = getenv("FLASK_MAIL_SERVER") -MAIL_PORT = getenv("FLASK_MAIL_PORT") -MAIL_USE_SSL = getenv("FLASK_MAIL_USE_SSL") -MAIL_DEBUG = DEBUG -MAIL_USERNAME = getenv("FLASK_MAIL_USERNAME") -MAIL_PASSWORD = getenv("FLASK_MAIL_PASSWORD") - -MAIL_RECIPIENT = getenv("FLASK_MAIL_RECIPIENT") diff --git a/server/main.py b/server/main.py deleted file mode 100644 index 4d256fe..0000000 --- a/server/main.py +++ /dev/null @@ -1,4 +0,0 @@ -from app import create_app - - -app = create_app() diff --git a/server/requirements.txt b/server/requirements.txt index 0a4de31..df5ebfe 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1,10 +1,10 @@ -blinker==1.4 -click==7.1.1 -Flask==1.1.2 -Flask-Mail==0.9.1 -itsdangerous==1.1.0 -Jinja2==2.11.1 -MarkupSafe==1.1.1 -python-dotenv==0.12.0 -six==1.14.0 -Werkzeug==1.0.1 +blinker +click +Flask +Flask-Mail +itsdangerous +Jinja2 +MarkupSafe +python-dotenv +six +Werkzeug diff --git a/server/app/api/routes.py b/server/rfq/__init__.py similarity index 72% rename from server/app/api/routes.py rename to server/rfq/__init__.py index 5664b0c..e5ff504 100644 --- a/server/app/api/routes.py +++ b/server/rfq/__init__.py @@ -1,21 +1,42 @@ +from dotenv import load_dotenv +from flask import Flask from flask import current_app from flask import json from flask import jsonify from flask import make_response from flask import request +from flask_mail import Mail from flask_mail import Message -from app.api import bp -from app import mail +from os import getenv +from werkzeug.middleware.proxy_fix import ProxyFix + +load_dotenv() + +app = Flask(__name__) +app.config.update( + DEBUG=True if getenv('FLASK_DEBUG') == 'True' else False, + SECRET_KEY=getenv('FLASK_SECRET_KEY'), + MAIL_SERVER=getenv("FLASK_MAIL_SERVER"), + MAIL_PORT=getenv("FLASK_MAIL_PORT"), + MAIL_USE_SSL=getenv("FLASK_MAIL_USE_SSL"), + MAIL_DEBUG=False, + MAIL_USERNAME=getenv("FLASK_MAIL_USERNAME"), + MAIL_PASSWORD=getenv("FLASK_MAIL_PASSWORD"), + MAIL_RECIPIENT=getenv("FLASK_MAIL_RECIPIENT") +) +app.wsgi_app = ProxyFix(app.wsgi_app) + +mail = Mail(app) -@bp.after_request +@app.after_request def after(response): response.headers["Access-Control-Allow-Origin"] = "*" response.headers["Access-Control-Allow-Headers"] = "*" return response -@bp.route("/rfq", methods=["POST"]) +@app.route("/rfq", methods=["POST"]) def send_rfq(): payload = request.json payload = json.loads(json.htmlsafe_dumps(payload)) diff --git a/server/setup.py b/server/setup.py new file mode 100644 index 0000000..04c4646 --- /dev/null +++ b/server/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup +from setuptools import find_packages + +setup( + name='MLabsRFQAPI', + version='1.0.0', + packages=find_packages(), + zip_safe=False, + install_requires=[ + 'Flask>=1.1.2', + 'Flask-Mail', + 'python-dotenv' + ] +)