def create_app(config_class=DevelopmentConfig): app = Flask(__name__) app.config.from_object(config_class) load_dotenv() jwt.init_app(app) # CORS(app) api = Api(app) db.init_app(app) app.cli.add_command(create_tables) # To interact with app from CLI b_crypt.init_app(app) ma.init_app(app) migrate = Migrate(app, db) # oauth.init_app(app) # USER API api.add_resource(UserRegister, '/user/register') api.add_resource(UserLogin, '/user/login') api.add_resource(UserLogout, '/user/logout') api.add_resource(UserPasswordRestoreRequest, '/user/restore') api.add_resource(UserPasswordReSetter, '/user/restore/<string:token>') api.add_resource(User, '/user/<int:_id>') api.add_resource(UserList, '/users/<int:limit>') api.add_resource(TokenRefresher, '/user/refreshing') api.add_resource(UserEmail2FA, '/user/fa2_auth/<string:token>') # REQUEST API api.add_resource(RequestsList, '/requests') api.add_resource(RequestCreation, '/requests/new') print(f"App current configuration: {config_class.CONFIG_NAME}") # OAuth API # api.add_resource(GithubLogin, "/login/oauth/github") # api.add_resource(GithubAuthorize, "/login/oauth/github/authorized") # CONFIRMATION API api.add_resource(Confirmation, '/user/confirmation/<string:confirmation_id>') # api.add_resource(User, '/users/<int:user_id>') api.add_resource(Content, '/content') @app.route('/') def home(): return render_template("index.html") # Logging log_level = logging.INFO if app.config['DEBUG'] else logging.ERROR handler = WatchedFileHandler('server.log') formatter = logging.Formatter('%(asctime)s | %(levelname)s: %(message)s', '%d-%m-%Y %H:%M:%S') handler.setFormatter(formatter) root = logging.getLogger() root.setLevel(log_level) root.addHandler(handler) logging.info('\n------------------- Starting Server -------------------') return app
def register_extensions(app, config_object): """Init extension. You can see list extension in the extensions.py Args: app: Flask handler application config_object: settings of the application """ # Order matters: Initialize SQLAlchemy before Marshmallow # create log folder db.app = app db.init_app(app) ma.init_app(app)
def create_app(config_class='configurations.py'): app = Flask(__name__) app.config.from_object(ProductionConfig) load_dotenv() jwt.init_app(app) api = Api(app) db.init_app(app) app.cli.add_command(create_tables) # To interact with app from CLI b_crypt.init_app(app) ma.init_app(app) migrate = Migrate(app, db) oauth.init_app(app) # USER API api.add_resource(UserRegister, '/users/register') api.add_resource(UserLogin, '/users/login') api.add_resource(UserLogout, '/users/logout') api.add_resource(User, '/user/<int:_id>') api.add_resource(UserList, '/users/<int:limit>') api.add_resource(TokenRefresher, '/users/refreshing') api.add_resource(UserEmail2FA, '/users/fa2_auth/<string:token>') # OAuth API api.add_resource(GithubLogin, "/login/oauth/github") api.add_resource(GithubAuthorize, "/login/oauth/github/authorized") # CONFIRMATION API api.add_resource(Confirmation, '/user_id/<string:confirmation_id>') # resources.add_resource(User, '/users/<int:user_id>') api.add_resource(CreatePost, '/posts/create') api.add_resource(Content, '/content') # Logging log_level = logging.INFO if app.config['DEBUG'] else logging.ERROR handler = WatchedFileHandler('server.log') formatter = logging.Formatter('%(asctime)s | %(levelname)s: %(message)s', '%d-%m-%Y %H:%M:%S') handler.setFormatter(formatter) root = logging.getLogger() root.setLevel(log_level) root.addHandler(handler) logging.info('\n------------------- Starting Server -------------------') return app
def register_extensions(app): db.init_app(app) migrate.init_app(app, db) ma.init_app(app)
def register_extensions(app): db.init_app(app) api.init_app(app, add_specs=app.config['SPECS']) ma.init_app(app)
def register_extensions(app): db.init_app(app) ma.init_app(app)