Skip to content

Commit

Permalink
feat: Add flask cors (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalajcodes authored Mar 17, 2021
1 parent 7e019c6 commit 1a5bb29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Flask==1.1.2
flask-restplus==0.13.0
Flask-SQLAlchemy==2.4.4
Flask-Mail==0.9.1
Flask-Cors==3.0.10
google-api-core==1.22.4
google-api-python-client==1.12.3
google-auth==1.22.1
Expand Down
34 changes: 25 additions & 9 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from dotenv import load_dotenv, find_dotenv
from firebase_admin import credentials
from flask import Flask
from flask_cors import CORS
from os import environ

from app.api.controllers import api
from app.database.sqlalchemy_extension import db
from config import LocalConfig, get_env_config

cors = CORS()


def create_app(config_env=None) -> Flask:
app = Flask(__name__)
Expand All @@ -22,22 +25,35 @@ def create_app(config_env=None) -> Flask:
""" Download service file from firebase and put it in project root directory """
cred = credentials.Certificate("google-credentials.json")
firebase_admin.initialize_app(cred)

mail_settings = {
"MAIL_SERVER": 'smtp.gmail.com',
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": environ.get('EMAIL_USER'),
"MAIL_PASSWORD": environ.get('EMAIL_PASS')
"MAIL_SERVER": "smtp.gmail.com",
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": environ.get("EMAIL_USER"),
"MAIL_PASSWORD": environ.get("EMAIL_PASS"),
}


cors.init_app(
app,
resources={
r"*": {
"origins": [
"http://localhost:3000",
"https://stem-diverse-tv.herokuapp.com/",
]
}
},
)

app.config.update(mail_settings)

api.init_app(app)
db.init_app(app)

from app.utils.mail_extension import mail

mail.init_app(app)

return app
Expand Down

0 comments on commit 1a5bb29

Please sign in to comment.