forked from philophilo/mrm_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (46 loc) · 1.42 KB
/
app.py
File metadata and controls
56 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, render_template
from flask_graphql import GraphQLView
from flask_cors import CORS
from flask_json import FlaskJSON
from flask_mail import Mail
from config import config
from helpers.database import db_session
from schema import schema
from healthcheck_schema import healthcheck_schema
from helpers.auth.authentication import Auth
from api.analytics.analytics_request import AnalyticsRequest
mail = Mail()
def create_app(config_name):
app = Flask(__name__)
CORS(app)
FlaskJSON(app)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
mail.init_app(app)
@app.route("/", methods=['GET'])
def index():
return render_template('index.html')
app.add_url_rule(
'/mrm',
view_func=GraphQLView.as_view(
'mrm',
schema=schema,
graphiql=True # for having the GraphiQL interface
)
)
app.add_url_rule(
'/_healthcheck',
view_func=GraphQLView.as_view(
'_healthcheck',
schema=healthcheck_schema,
graphiql=True # for healthchecks
)
)
@app.route("/analytics", methods=['POST'])
@Auth.user_roles('Admin', 'REST')
def analytics_report():
return AnalyticsRequest.validate_request(AnalyticsRequest)
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
return app