Completed
Push — develop ( 3a3795...1e8194 )
by Antony
03:19 queued 01:31
created

build.run.create_app()   B

Complexity

Conditions 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 27
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
9
def create_app(config_filename):
10
    app = Flask(__name__)
11
    app.config.from_object(app_config[config_filename])
12
    #bcrypt = Bcrypt(app)
13
14
15
    #setup flask-jwt-extended extension
16
    app.config['JWT_SECRET_KEY'] = 'secret'
17
    jwt = JWTManager(app)
18
19
    from app import api_bp
20
    app.register_blueprint(api_bp, url_prefix='/api/v1')
21
22
23
    @app.errorhandler(403)
24
    def forbidden(error):
25
        return "Your are not authorized to view this page", 403
26
27
    @app.errorhandler(404)
28
    def page_not_found(error):
29
        return "The resource you are looking for is not available", 404
30
31
    @app.errorhandler(500)
32
    def internal_server_error(error):
33
        return "The server encountered internal eror", 500
34
35
    return app
36
37
if __name__=="__main__":
38
    app = create_app("production")
39
    jwt = JWTManager(app)
40
    port = int(os.environ.get('PORT', 5000))
41
    app.run(host='0.0.0.0', port=port)