Total Complexity | 1 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from flask import Flask |
||
2 | import os |
||
3 | from config import app_config |
||
4 | from flask_jwt_extended import (JWTManager, jwt_required, |
||
5 | create_access_token,get_jwt_identity) |
||
6 | |||
7 | |||
8 | def create_app(config_filename): |
||
9 | app = Flask(__name__) |
||
10 | app.config.from_object(app_config[config_filename]) |
||
11 | |||
12 | #setup flask-jwt-extended extension |
||
13 | app.config['JWT_SECRET_KEY'] = 'secret' |
||
14 | jwt = JWTManager(app) |
||
15 | |||
16 | from app import api_bp |
||
17 | app.register_blueprint(api_bp, url_prefix='/api/v1') |
||
18 | |||
19 | |||
20 | @app.errorhandler(403) |
||
21 | def forbidden(error): |
||
22 | return "Your are not authorized to view this page", 403 |
||
23 | |||
24 | @app.errorhandler(404) |
||
25 | def page_not_found(error): |
||
26 | return "The resource you are looking for is not available", 404 |
||
27 | |||
28 | @app.errorhandler(500) |
||
29 | def internal_server_error(error): |
||
30 | return "The server encountered internal eror", 500 |
||
31 | |||
32 | return app |
||
33 | |||
34 | if __name__=="__main__": |
||
35 | app = create_app("production") |
||
36 | jwt = JWTManager(app) |
||
37 | port = int(os.environ.get('PORT', 5000)) |
||
38 | app.run(host='0.0.0.0', port=port) |