-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (44 loc) · 1.5 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api
from config import app_config
from flask_cors import CORS
from flask_restful.utils import cors
db = SQLAlchemy()
api = Api()
from resources import register_routes
from handlers import register_error_handlers
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(app_config[config_name])
app.config.from_pyfile('config.py')
import logging
logging.basicConfig(
level=logging.getLevelName(app.config.get("LOG_LEVEL"))
)
logger = logging.getLogger("App")
logger.info("Starting app!")
register_routes(api)
register_error_handlers(app)
api.init_app(app)
db.init_app(app)
CORS(app, origins=["*"], send_wildcard=True)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['CORS_RESOURCES'] = {r"/*": {"origins": "*"}}
api.decorators = [
cors.crossdomain(
origin='*',
methods = ['GET', 'PUT', 'PATCH', 'POST', 'DELETE', 'OPTIONS'],
attach_to_all = True,
automatic_options = False
)
]
from daos.http_daos import httpDAO
@app.after_request
def after_request(response):
httpDAO.add_entry(path=request.path,
method=request.method,
response_code=response.status_code,
client_ip=request.remote_addr)
return response
return app