Passed
Pull Request — develop (#28)
by Antony
01:56
created

build.run.create_app()   B

Complexity

Conditions 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
nop 1
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)