-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (35 loc) · 1.23 KB
/
app.py
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
from quart import Quart, request
from quart import request
from quart import current_app as app
from sqlalchemy.inspection import inspect
from os import environ
from classes.live_job import db
from routes.update import update_api, update_jobs
from routes.health import health_api
from routes.job import job_api
app = Quart(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = environ.get('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.app = app
db.init_app(app)
# Create tables if they don't exist
if not inspect(db.engine).has_table('live_jobs'):
logging.warning("Creating tables")
db.create_all()
# Register routes
app.register_blueprint(update_api)
app.register_blueprint(job_api)
app.register_blueprint(health_api)
@app.before_serving
async def startup():
app.add_background_task(update_jobs)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers',
'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,PATCH')
return response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)