forked from M-Labs/web2019
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)
This commit is contained in:
parent
5703458586
commit
4efa24b09b
|
@ -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
|
|
@ -1,7 +0,0 @@
|
|||
from flask import Blueprint
|
||||
|
||||
|
||||
bp = Blueprint("api", __name__, url_prefix="/api")
|
||||
|
||||
|
||||
from app.api import routes # nopep8
|
|
@ -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")
|
|
@ -1,4 +0,0 @@
|
|||
from app import create_app
|
||||
|
||||
|
||||
app = create_app()
|
|
@ -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
|
||||
|
|
|
@ -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))
|
|
@ -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'
|
||||
]
|
||||
)
|
Loading…
Reference in New Issue