Esempio n. 1
0
def _main():
    # application_path: ~/backend/
    application_path = Path(path.abspath(__file__)).parent
    dist_folder = str(Path(application_path, "dist"))

    serve_port = 9797

    # creates the Flask application instance
    app = Flask(__name__,
                static_folder=dist_folder,
                template_folder=dist_folder)

    register_blueprints(app, 'blueprints', ['./blueprints'])

    app.config.update({'DEBUG': False})

    @app.route('/')
    def index():
        """
        index.html is located in dist/index.html;
        after executing "npm run build", dist folder will be automatically generated in backend/dist
        this setting is configured in vue.config.js, which deploys dist folder to backend/dist
        if frontend has been changed, please remember to run "npm run build"
        please do not change anything manually in dist folder or the location of it
        """
        return render_template("index.html")

    @app.errorhandler(Exception)
    def handle_all_exception(e: Exception):
        print(e)
        return jsonify({
            'error': True,
            'message': type(e).__name__ + ': ' + str(e),
        }), 500

    app.config['SWAGGER'] = {
        'title': 'API of CCC Assignment 2',
        'swagger_version': '2.0',
    }
    swagger = flasgger.Swagger(app)

    # allow cors on all domains. we just ignore security issue
    CORS(app)

    # creates the Socket.IO socket instance
    socket_io = SocketIO(app, cors_allowed_origins="*")
    socketio_server = {
        'msg-parser':
        MsgParserSocketIOServer(socketio=socket_io,
                                namespace='/msg-parser',
                                application_path=application_path)
    }

    try:
        print(f'Launch browser into http://localhost:{serve_port}')

        socket_io.run(app, host='0.0.0.0', port=serve_port, debug=False)
    except KeyboardInterrupt:
        return 0
Esempio n. 2
0
def create_app():
    """ Fonction créant l'app en tant que telle, on va chercher les blueprints dans le dossier modules et
    on les enregistre, on attache aussi les errorhandlers.

    """

    app = Flask(__name__)
    register_blueprints(app)
    register_blueprints(app, "modules", ["modules"])
    app.secret_key = conf.SECRET

    @app.errorhandler(403)
    def unauthorized(error):
        return render_template("errors/403.html")

    return app
Esempio n. 3
0
def create_app(package_name, package_path, settings_override=None,
               register_security_blueprint=True):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the Application platform.

    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param register_security_blueprint: flag to specify if the Flask-Security
                                        Blueprint should be registered. Defaults
                                        to `True`.
    """

    app = Flask(package_name, instance_relative_config=True, static_url_path='/static/'+str(STATIC_GUID))
    app.config.from_object('application.settings')
    app.config.from_pyfile('settings.cfg', silent=True)
    app.config.from_object(settings_override)
    db.app = app
    db.init_app(app)
    mail.init_app(app)
    babel.init_app(app)
    # Init cache
    cache.init_app(app)
    # Init Sentry
    sentry.init_app(app)
    # cache.init_app(app, config={'CACHE_TYPE': 'simple'})
    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    security.datastore = user_datastore
    security.init_app(app, user_datastore,
                      register_blueprint=register_security_blueprint)
    social.init_app(app, SQLAlchemyConnectionDatastore(db, Connection))
    #gravatar.__init__(app, size=128, rating='g', default='mm', force_default=False,
    #                  force_lower=False, use_ssl=False)
    register_blueprints(app, package_name, package_path)
    app.wsgi_app = ProxyFix(HTTPMethodOverrideMiddleware(app.wsgi_app))

    if not app.debug:
        import logging
        from logging.handlers import RotatingFileHandler
        file_handler = RotatingFileHandler('logs/errors_debug.log', maxBytes=1024 * 1024 * 100, backupCount=20)
        file_handler.setLevel(logging.WARNING)
        formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        file_handler.setFormatter(formatter)
        app.logger.addHandler(file_handler)

    return app
Esempio n. 4
0
def create_app(create_db=False):
    """Creates an app by registering blueprints in the modules directory
    and loading the configuration
    
    """

    app = Flask(__name__)
    app.secret_key = os.urandom(24)
    register_blueprints(app, "modules", ["modules"])

    app.config["SQLALCHEMY_DATABASE_URI"] = conf.DB
    db.init_app(app)
    db.app = app

    if create_db:
        db.create_all()

    return app
Esempio n. 5
0
def create_app(create_db=False):
    """Creates an app by registering blueprints in the modules directory
    and loading the configuration

    """

    app = Flask(__name__)
    app.secret_key = os.urandom(24)
    register_blueprints(app, "modules", ["modules"])

    app.config["SQLALCHEMY_DATABASE_URI"] = conf.DB
    # Maximum 3Mo pour les images
    app.config['MAX_CONTENT_LENGTH'] = 3 * 1024 * 1024

    db.init_app(app)
    db.app = app

    if create_db:
        db.create_all()

    return app
Esempio n. 6
0
def create_app_factory(package_name, package_path, settings_override=None):
    """Returns a :class:`Flask` application instance configured with
    project-wide functionality.

    :param package_name: application package name.
    :param package_path: application package path.
    :param settings_override: a dictionary of settings to override.
    """
    app = Flask(package_name, instance_relative_config=True)

    app.config.from_object(settings)
    app.config.from_object(settings_override)

    app.es = ElasticsearchService(app.config['ELASTICSEARCH_HOST'],
                                  app.config['ELASTICSEARCH_PORT'])

    register_blueprints(app, package_name, package_path)

    if BUGSNAG_APIKEY:
        from bugsnag.flask import handle_exceptions
        handle_exceptions(app)

    return app
Esempio n. 7
0
def create_app(package_name,
               package_path,
               settings_override=None,
               register_security_blueprint=False):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the Overholt platform.
    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param register_security_blueprint: flag to specify if the Flask-Security
                                        Blueprint should be registered. Defaults
                                        to `True`.
    """
    app = Flask(package_name, instance_relative_config=True)
    app.config.from_pyfile('settings.py', silent=False)
    app.config.from_object(settings_override)

    rv, apis = register_blueprints(app, package_name, package_path)

    return app, apis
Esempio n. 8
0
def register_all_blueprints(app):
    """
        注册app应用api包路径下的所有蓝图
    """
    register_blueprints(app, api.__name__, api.__path__)