-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
executable file
·49 lines (40 loc) · 1.11 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
#!/usr/bin/python3
""" Flask Application """
from models import storage
from api.v1.views import app_views
from os import environ
from flask import Flask, render_template, make_response, jsonify
from flask_cors import CORS
from flasgger import Swagger
from flasgger.utils import swag_from
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
app.register_blueprint(app_views)
cors = CORS(app, resources={r"/api/v1/*": {"origins": "*"}})
@app.teardown_appcontext
def close_db(error):
""" Close Storage """
storage.close()
@app.errorhandler(404)
def not_found(error):
""" 404 Error
---
responses:
404:
description: a resource was not found
"""
return make_response(jsonify({'error': "Not found"}), 404)
app.config['SWAGGER'] = {
'title': 'AirBnB clone Restful API',
'uiversion': 3
}
Swagger(app)
if __name__ == "__main__":
""" Main Function """
host = environ.get('HBNB_API_HOST')
port = environ.get('HBNB_API_PORT')
if not host:
host = '0.0.0.0'
if not port:
port = '5000'
app.run(host=host, port=port, threaded=True)