Ejemplo n.º 1
0
def init(app):
    api.init_app(app)
    db.init_app(app)
    media.init_app(app)

    init_um(app)
    init_uploads(app)
    init_routes(app)
Ejemplo n.º 2
0
def init(app):
    api.init_app(app)
    db.init_app(app)
    media.init_app(app)
    login.init_app(app)
    login.login_view = '.login'

    @login.user_loader
    def load_user(id):
        return User.objects(id=id).first()

    init_uploads(app)
    init_routes(app)
Ejemplo n.º 3
0
def create_app():
    app = Flask(__name__)

    from . import config
    app.config.from_object(config)

    # 注册插件
    from utils import exts
    exts.init_app(app)

    import api
    api.init_app(app)
    return app
Ejemplo n.º 4
0
def run_server():
    '''Run the main aiohttp server'''
    config = get_config()
    loop = asyncio.get_event_loop()
    app = loop.run_until_complete(init_app(loop, config))
    args = parse_arguments()
    web.run_app(app, path=args.path, port=args.port)
Ejemplo n.º 5
0
def create_app(test_db=None):
    """creates a new app instance"""
    new_app = Flask(__name__)
    new_app.config["SQLALCHEMY_DATABASE_URI"] = config.database.url(
        default=test_db or "sqlite:///{{cookiecutter.package_name}}.db", cast=fix_dialect
    )
    new_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    new_app.config["ERROR_404_HELP"] = False
    db.init_app(new_app)
    api.init_app(new_app)
    Migrate(new_app, db, directory=Path(__file__).parent / "migrations")
    new_app.wsgi_app = ProxyFix(
        new_app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_port=1
    )  # remove after flask-restx > 0.2.0 is released
    # https://github.com/python-restx/flask-restx/issues/230
    CORS(new_app)
    return new_app
Ejemplo n.º 6
0
def create_app():
    flask_env = os.getenv('FLASK_ENV', 'development')

    app = Flask(__name__)
    app.config.from_object(CONFIG_MAPPER.get(flask_env, 'development'))

    configure_loggers(app)

    import api
    api.init_app(app)
    api.add_context(app)

    import resources
    resources.init_app(app)

    # app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)

    return app
Ejemplo n.º 7
0
def configure_extensions(app):
    # flask-sqlalchemy
    db.init_app(app)

    # flask-admin
    admin.init_app(app)
    admin.configure_admin(app)

    # flask-restless
    api.init_app(app, flask_sqlalchemy_db=db)
    api.configure_api(app)

    ## flask-mail
    #mail.init_app(app)

    ## flask-cache
    #cache.init_app(app)

    ## flask-babel
    #babel = Babel(app)

    #@babel.localeselector
    #def get_locale():
    #    accept_languages = app.config.get('ACCEPT_LANGUAGES')
    #    return request.accept_languages.best_match(accept_languages)

    ## flask-login
    #login_manager.login_view = 'frontend.login'
    #login_manager.refresh_view = 'frontend.reauth'

    #@login_manager.user_loader
    #def load_user(id):
    #    return User.query.get(id)
    #login_manager.setup_app(app)

    # flask-openid
    oid.init_app(app)
Ejemplo n.º 8
0
def create_app():
    global run_once
    app = Flask(__name__)

    # app.sockets = Sockets(app)
    #app.config['DEBUG'] = True
    app.config['SECRET_KEY'] = 'super-secret'
    db.init_app(app)
    auth.init_app(app)
    api.init_app(app, db.db)

    @app.after_request
    def clear_server_header(response):
        response.headers['Server'] = ''
        # del response.headers['Set-Cookie']
        # response.set_cookie('session', '', expires=0, httponly=True)
        return response

    if os.environ.get('FLASK_PROFILE', '') == '1':
        from werkzeug.middleware.profiler import ProfilerMiddleware

        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

    return app
Ejemplo n.º 9
0
 def setUp(self):
     self.app = init_app(config.get('test'))
     self.app.test_request_context().push()
     self.service = mock.Mock(spec_set=Service)
Ejemplo n.º 10
0
#!/usr/bin/python3
import os
from flask import Flask
from flask_cors import CORS

app = Flask(__name__)
cors = CORS(app, supports_credentials=True)
with app.app_context():
    app.config.from_object('conf')

    from models import db
    db.init_app(app)
    import api
    app.register_blueprint(api.api)
    api.init_app(app)


@app.route("/")
def hello():
    return 'hello followDem-server !'
Ejemplo n.º 11
0
def init_app(app):
    """init some thingies"""
    api.init_app(app)
Ejemplo n.º 12
0
    def setUp(self):
        self.app = init_app(config.get('test'))
        self.app.app_context().push()

        self.repository = PersonRepository()
Ejemplo n.º 13
0
from api import init_app
from api.commands import DropTables, CreateTables, Initailize

from flask_script import Manager, Server
from flask_migrate import MigrateCommand

app = init_app()
manager = Manager(app)

manager.add_command('create_tables', CreateTables())
manager.add_command('drop_tables', DropTables())
manager.add_command('init', Initailize())
manager.add_command('db', MigrateCommand)
manager.add_command('run', Server(port=9000))


@app.after_request
def allow_cors(response):
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
    return response


if __name__ == '__main__':
    manager.run()
Ejemplo n.º 14
0
import os
from api import init_app
from config import config


app = init_app(config=config.get(os.getenv('FLASK_ENV'), 'dev'))

if __name__ == "__main__":
    if os.getenv('FLASK_ENV') == 'prod':
        raise Exception('You\'re trying to run this Flask app in a production environment with \n' +
                        'Flask\'s builtin application server which is not suitable for production.')

    app.run(host='0.0.0.0', port=8080)
Ejemplo n.º 15
0
from api import init_app
from config import config

# used for production, and served by WSGI server
app = init_app(config=config.get('FLASK_ENV', 'prod'))
Ejemplo n.º 16
0
 def create_app(loop):
     return init_app(Config, loop)