-
Notifications
You must be signed in to change notification settings - Fork 29
/
server.py
37 lines (31 loc) · 1.08 KB
/
server.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
import flask
from flask_cors import CORS
from endpoints import blueprint, exceptions
from werkzeug.exceptions import NotFound
def redirectToDocs(): return flask.redirect('https://gadhagod.github.io/Hyrule-Compendium-API')
app = flask.Flask(__name__, static_folder='compendium/images')
app.app_context()
CORS(app)
app.register_error_handler(
500,
lambda e: ({'data': {}, 'status': 500, 'message': 'Server error'}, 500)
)
app.register_error_handler(
NotFound,
lambda e: ({
'data': {},
'status': 404,
'message': e.description if isinstance(e, exceptions.ApiException)
else "endpoint does not exist"
}, 404)
)
app.add_url_rule('/', view_func=redirectToDocs)
app.add_url_rule('/api', view_func=redirectToDocs)
app.add_url_rule('/api/v3', view_func=redirectToDocs)
app.register_blueprint(blueprint, url_prefix='/api/v3')
if __name__ == '__main__': # dev server
app.run(debug=True)
else: # prod server
# precondition: "v2-src" branch cloned into "v2" dir
from v2.server import v2_blueprint
app.register_blueprint(v2_blueprint)