def METHOD_NAME(cmdline_options, cfg, mxcube):
    template_dir = os.path.join(os.path.dirname(__file__), "templates")
    Server.flask = Flask(
        __name__,
        static_folder=cmdline_options.static_folder,
        static_url_path="",
        template_folder=template_dir,
    )
    Server.flask.wsgi_app = ProxyFix(Server.flask.wsgi_app)
    Server.flask.config.from_object(cfg.flask)
    Server.flask.register_error_handler(Exception, Server.exception_handler)
    db_session = init_db(cfg.flask.USER_DB_PATH)
    Server.user_datastore = UserDatastore(
        db_session, User, Role, message_model=Message
    )
    Server.db_session = db_session
    Server.flask_socketio = SocketIO(
        manage_session=False, cors_allowed_origins=cfg.flask.ALLOWED_CORS_ORIGINS
    )
    Server.flask_socketio.init_app(Server.flask)
    Server.api = SpecTree(
        "flask",
        app=Server.flask,
        title="MXCuBE3 api",
        version="v1.0",
        annotations=True,
    )
    Server.validate = Server.api.validate
    # the following test prevents Flask from initializing twice
    # (because of the Reloader)
    if not Server.flask.debug or os.environ.get("WERKZEUG_RUN_MAIN") == "true":
        atexit.register(Server.kill_processes)
        with open("/tmp/mxcube.pid", "w") as f:
            f.write(str(os.getpid()) + " ")
        # Make the valid_login_only decorator available on server object
        Server.restrict = staticmethod(networkutils.login_required)
        Server.require_control = staticmethod(networkutils.require_control)
        Server.ws_restrict = staticmethod(networkutils.ws_valid_login_only)
        Server.route = staticmethod(Server.flask.route)