Example #1
0
def create_app(config_filename):
    print("Hello World from %s!" % __name__)
    # todo application root和instalce pat
    # app = Flask(__name__, instance_relative_config=True)
    app = Flask(__name__)
    # todo
    app.config.from_object(config_filename)
    # todo
    # app.config.from_pyfile(config_filename, silent=True)

    # 每次请求后调用一个函数
    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers[
                'Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Allow-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response

    from app.users.model import db
    db.init_app(app)

    from app.users.api import init_api
    init_api(app)

    return app
def init_app(app):
#     db.init_app(app)
    from app.users.model import init_roles
    init_roles()
    
    from app.users.api import init_api
    from app.article.api import init_article
    init_api(app)
    init_article(app)
    return app
Example #3
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)

    db.init_app(app)

    # 用户模块
    from app.users.api import init_api
    init_api(app)

    return app
Example #4
0
def create_app(config_filename):
    print(
        __name__
    )
    app = Flask(__name__)
    app.config.from_object(config_filename)

    @app.before_first_request
    def create_db():
        # Recreate database each time for demo
        # db.drop_all()
        if Users.query.filter_by(id=1).first()==None:
        # print(11111111111111111111111,Users.query.filter_by(id=1).first())
        # print(22222222222222,Users.query.all())
        # tmp=Users.query.filter_by(id=0).first()
        # print(tmp)
            db.create_all()




            admin = Users('admin', "580312",'*****@*****.**')
            db.session.add(admin)
            guestes = [Users('guest1', "580312",'*****@*****.**'),
                       Users('guest2', "580312",'*****@*****.**'),
                       Users('guest3', "580312",'*****@*****.**'),
                       Users('guest4', "580312",'*****@*****.**')]
            db.session.add_all(guestes)
            db.session.commit()
    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response
    # 初始化数据库
    from app.users.model import db
    db.init_app(app)

    from app.users.api import init_api
    init_api(app)

    return app
Example #5
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)

    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response

    from app.users.api import init_api
    init_api(app)

    return app
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)

    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers[
                'Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response

    from app.auth.auths import Auth
    from app import common
    jwt = JWTManager(app)

    @jwt.expired_token_loader
    def expired_token_handle(error_string):
        return common.make_response_error(
            -1, '认证token已过期(%s),请重新登陆!' % error_string)

    @jwt.invalid_token_loader
    def invalid_token_handle(error_string):
        return common.make_response_error(
            -1, '认证token无效(%s)!请重新登陆!' % error_string)

    @jwt.unauthorized_loader
    def invalid_token_handle(error_string):
        return common.make_response_error(
            -1, '认证token未经授权(%s)!请重新登陆!' % error_string)

    from app.users.model import db
    db.init_app(app)

    from app.users.api import init_api
    init_api(app)

    return app
Example #7
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)
    es_util = Elasticsearch_Util()
    print('当前路径', os.getcwd())

    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers[
                'Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response

    from app.users.model import db
    db.init_app(app)

    # 注册用户API接口
    from app.users.api import init_api
    init_api(app)

    # 注册规则API接口
    from app.rules.esapi import init_api
    init_api(app, es_util)

    # 注册关联分析
    from app.rules.alert_assotiation import init_api
    init_api(app, es_util)

    # 注册数据预览和深潜接口
    from app.rules.rule_data_overview_dive import init_api
    init_api(app, es_util)

    # # 注册日志异常检测API接口
    #from app.rules.nlp_error_predict import init_api
    #init_api(app, es_util)

    return app
Example #8
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)
    es_util = Elasticsearch_Util()
    print ('当前路径',os.getcwd())

    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
        return response

    from app.users.model import db
    db.init_app(app)

    # 注册用户API接口
    from app.users.api import init_api
    init_api(app)

    # 注册规则API接口
    from app.rules.esapi import init_api
    init_api(app, es_util)

    # 注册关联分析
    from app.rules.alert_assotiation import init_api
    init_api(app, es_util)

    # 注册数据预览和深潜接口
    from app.rules.rule_data_overview_dive import init_api
    init_api(app, es_util)

    # # 注册日志异常检测API接口
    #from app.rules.nlp_error_predict import init_api
    #init_api(app, es_util)

    return app