-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (45 loc) · 1.22 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
"""
This is the main entry point for Coder Directory Api
Copyright (c) 2017 by Mike Tung.
MIT License, see LICENSE for details.
"""
from flask import Flask
from coder_directory_api.settings import *
from coder_directory_api.resources import api_resources
from flask_cors import CORS
from werkzeug.contrib.fixers import ProxyFix
def create_app() -> Flask:
"""Factory method to create an instance of Coder Directory Api
Returns:
Instance of coder directory api
"""
api = Flask('__name__')
api.secret_key = SECRET_KEY
CORS(api)
api.wsgi_app = ProxyFix(api.wsgi_app)
api.url_map.strict_slashes = False
for rsc in api_resources:
register_resources(
api,
bp=rsc['bp'],
route=rsc['route']
)
return api
def register_resources(api, bp, route=None):
if route:
return api.register_blueprint(
bp,
url_prefix='{}/{}'.format(BASE_URL, route)
)
return api.register_blueprint(
bp,
url_prefix=BASE_URL
)
if __name__ == '__main__':
app = create_app()
app.run(
host=HOST,
port=PORT,
debug=DEBUG,
threaded=MULTITHREADING,
)