async def startup(): logger.info('-- STARTING UP --') print('-- STARTING UP --') from database.db import initialize_db initialize_db() from resources.routes import initialize_routes initialize_routes(app) if ShopSettings.ENABLE: if NowPaymentsSettings.ENABLE: from resources.nowpayments import getNowPaymentsStatus, setCachedAvailableCoins if await getNowPaymentsStatus(): print('NOWPayments is online. Fetching available coins...') for i in range(NowPaymentsSettings.STARTUP_COIN_FETCH_AMOUNT): if await setCachedAvailableCoins(): print('NOWPayments coins cached.') break else: print('Failed to get NOWPayments coins.') if i < NowPaymentsSettings.STARTUP_COIN_FETCH_AMOUNT - 1: print( f'Retrying {NowPaymentsSettings.STARTUP_COIN_FETCH_AMOUNT - 1 - i} time(s).' ) else: print('NOWPayments not responding.') print( f'Available coins will be set on the next reqest to {APISettings.ROUTE_BASE}payment/nowpayments/available-coins request if NOWPayments is available.' ) print('-- STARTED UP --') logger.info('-- STARTED UP --')
def create_app(): app = Flask(__name__) app.config.from_pyfile("./config.cfg") CORS(app) JWTManager(app) initialize_db(app) initialize_routes(app) return app
def initialize_apps(app): api = Api(app=app, errors=errors) Bcrypt(app=app) JWTManager(app=app) initialize_db(app=app) initialize_routes(api=api) api.init_app(app)
def register_extensions(app): """Adds any previously created extension objects into the app, and does any further setup they need.""" # Connect to the local mongoDB database app.config["MONGO_URI"] = "mongodb://localhost:27017/talaria" initialize_db(app) # All done! app.logger.info("Extensions registered")
def create_app(config={}): """This function create Flask app. Is required by wsgi because it need to be called after service is started and forked, not when importing the module during initialization. To start the flask app, first import the module and then create all the stuff by invoking this function You need call the run method on the returned values to start acception requests Args: config (dict): pass parameters to this app (not yet defined) Returns: Flask: a flask initialized application """ app = Flask(__name__) api = Api(app, errors=errors) Bcrypt(app) JWTManager(app) app.logger.debug("App initialized") # http://docs.mongoengine.org/projects/flask-mongoengine/en/latest/#configuration app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb://mongo/smarter', 'username': os.getenv("MONGODB_SMARTER_USER"), 'password': os.getenv("MONGODB_SMARTER_PASS"), 'authentication_source': 'admin', 'alias': DB_ALIAS, # NOTE: This fixes "UserWarning: MongoClient opened before fork." # I'm not aware of side effects yet. Default value is/was "True" 'connect': False } # override configuration with custom values if 'host' in config: app.logger.error(f"Setting custom host: {config['host']}") app.config['MONGODB_SETTINGS']['host'] = config['host'] # https://flask-jwt-extended.readthedocs.io/en/stable/basic_usage/ app.config["JWT_SECRET_KEY"] = os.getenv('JWT_SECRET_KEY') # connect to database initialize_db(app) app.logger.debug("Database initialized") # you MUST register the blueprint app.register_blueprint(usersbp) # add resources initialize_routes(api) app.logger.debug("Routes initialized") return app
def register_extensions(app): """Adds any previously created extension objects into the app, and does any further setup they need.""" app.config["MONGO_URI"] = "mongodb://localhost:27017/futbase" initialize_db(app) app.config['SECRET_KEY'] = 'mysecret' # All done! app.logger.info("Extensions registered")
def create_app(): app = Flask(__name__) CORS(app) app.config['CORS_HEADERS'] = 'Content-Type' app.config["MONGO_URI"] = "mongodb+srv://ilyagusa:[email protected]/data_news?retryWrites=true&w=majority" app.register_blueprint(image, url_prefix='/data_image') app.register_blueprint(video, url_prefix='/data_video') app.register_blueprint(messages, url_prefix='/messages') initialize_db(app) return app
def setUp(self): app = Flask(__name__) CORS(app) app.config['JWT_SECRET_KEY'] = 'idbfiw724yr4fn3y5gt754tbhi54bth45b' api = Api(app) bcrypt = Bcrypt(app) jwt = JWTManager(app) app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb://localhost/mypanda' } initialize_db(app) initialize_routes(api) app.config['TESTING'] = True app.config['DEBUG'] = False self.app = app.test_client() self.assertEqual(app.debug, False)
def init(app): """ function to initialise" 1. DB [MongoDB] 2. Restful-API [flask-restful] 3. Bcrypt """ # DB initialization initialize_db(app) # API initialization along with custom errors and routes api = Api(app, errors=errors) initialize_auth_routes(api) initialize_resource_routes(api) # Setting up Bcrypt for password encryption bcrypt = Bcrypt(app) # JWT initialisation jwt = JWTManager(app) register_jwt_callbacks(jwt)
def create_app(): app = Flask(__name__) # Config app parameters app = config(app) # Definition of the routes api = Api(app, errors=errors) initialize_routes(api) # Hashing lib bcrypt = Bcrypt(app) # Auth lib jwt = JWTManager(app) # Database init initialize_db(app) # Set CORS CORS(app) return app
def create_app(config=DevelopmentConfig()): app = Flask(__name__) CORS(app) app.config.from_object(config) app.logger.setLevel(logging.DEBUG) db = initialize_db(app) setup_blueprints(app) setup_swaggerui(app) @app.route('/static/<path:path>') def send_static(path): return send_from_directory('static', path) # -- Unassigned endpoints @app.route('/') def hello(): return "This is the Auth Server!" return app
def create_app(config=DevelopmentConfig()): app = Flask(__name__) CORS(app) app.config.from_object(config) app.logger.setLevel(logging.DEBUG) db = initialize_db(app) # -- Services from services.UsersService import UsersService from services.VideoService import VideoService from services.NotificationService import NotificationService user_service = UsersService(app.config['AUTH_SERVER']) video_service = VideoService(app.config['MEDIA_SERVER']) notification_service = NotificationService(app.config['NOTIF_SERVER']) # -- Routes registration from routes import auth, monitoring, users, videos app.register_blueprint(monitoring.bp_monitor) app.register_blueprint(auth.construct_blueprint(user_service)) app.register_blueprint(users.construct_blueprint(user_service, video_service, notification_service)) app.register_blueprint(videos.construct_blueprint(video_service, user_service)) setup_swaggerui(app) # -- Unassigned endpoints @app.route('/static/<path:path>') def send_static(path): return send_from_directory('static', path) @app.route('/') def hello(): return "This is the Application Server!" @app.route('/friendRequests', methods=['POST']) def friend_request(): return "This endpoint will work for sending invites" return app
def setUp(self): self.app = app.test_client() if 'mongoengine' not in app.extensions: initialize_db(app) initialize_routes(api) self.db = db.get_db()
from database.db import initialize_db from database.models import Alumno from resources.routes import initialize_routes import os server = Flask(__name__, static_folder="docs") CORS(server) enviroment_configuration=os.environ.get('CONFIGURATION_SETUP') server.config.from_object(enviroment_configuration) #print(server.config["JSON_AS_ASCII"]) print(enviroment_configuration) api=Api(server) bcrypt=Bcrypt(server) jwt=JWTManager(server) initialize_db(server) initialize_routes(api) #if __name__=="__main__": # app.run(host='0.0.0.0',port=5000) #{ #"matricula":"201756568", #"mail":"*****@*****.**", #"name": "pepe pollo", # "password": "******" #} ## #
from flask import Flask from apis import api from database.db import initialize_db app = Flask(__name__) api.init_app(app) initialize_db(api) if __name__ == '__main__': app.run(debug=True)
from flask import Flask from flask_bcrypt import Bcrypt from flask_jwt_extended import JWTManager from database.db import initialize_db from flask_restful import Api from resources.routes import initialize_routes from flask_cors import CORS, cross_origin import os heroku = Flask(__name__) CORS(heroku) heroku.config.from_envvar('ENV_FILE_LOCATION') api = Api(heroku) bcrypt = Bcrypt(heroku) jwt = JWTManager(heroku) host = os.getenv('MONGODB_HOST') heroku.config['MONGODB_SETTINGS'] = {'host': host, 'retryWrites': 'false'} initialize_db(heroku) initialize_routes(api)
from flask import Flask from flask_cors import CORS from route.openapi import swaggerui_blueprint, SWAGGER_URL from route.post import posts from database.db import initialize_db app = Flask(__name__) CORS(app) app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb+srv://admin:[email protected]/main_db?retryWrites=true&w=majority' } db = initialize_db(app) app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL) app.register_blueprint(posts) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(host='0.0.0.0')
from flask import Flask, request, Response from database.db import initialize_db from database.models import Movie application = Flask(__name__) application.config['MONGODB_SETTINGS'] = {'host': 'mongodb+srv://dbuser:[email protected]/movie-db?retryWrites=true&w=majority'} #{'host': 'mongodb://localhost/movie-bag2'} # initialize_db(application) @application.route('/movies', methods=['GET']) def get(): movies = Movie.objects().to_json() return {'movies': movies} @application.route('/movies', methods=['POST']) def add(): body = request.get_json() movie = Movie(**body).save() #id = movie.id return {"message": 'movie saved'} @application.route('/movies/<int:index>', methods=['PUT']) def update(index): body = request.get_json() Movie.objects.get(id=id).update(**body)
load_dotenv(dotenv_path=find_dotenv(".env")) flask_app = Flask(__name__) # configure app flask_app.config["SECRECT_KEY"] = os.getenv("FLASK_SECRET_KEY") flask_app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY") flask_app.config["JWT_TOKEN_LOCATION"] = "headers" flask_app.config["JWT_HEADER_TYPE"] = "" flask_app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("SQLALCHEMY_DB_URI") # avoid sqlalchemy warning flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # jwt exceptions to be handled -> forcing 4xx reponses flask_app.config["PROPAGATE_EXCEPTIONS"] = True # instantiate db initialize_db(flask_app) # instantiate flask_restful api = Api(flask_app) # adding routes to our app initialize_routes(api) # JWT jwt = JWTManager(flask_app) # create celery celery_app = make_celery_app(flask_app) from resources.product import fetch_products_from_db from external.offers import get_offers, update_db_with_offers from celery.utils.log import get_task_logger
from flask import Flask from flask_bcrypt import Bcrypt from flask_jwt_extended import JWTManager from database.db import initialize_db from database.models import Movie import json from flask_restful import Api from resources.routes import intitialize_routes from resources.errors import errors app = Flask(__name__) app.config['JWT_SECRET_KEY'] = '9b1a6c26db87b72cd8cee6814d39e1e7' #app.config.from_envvar('ENV_FILE_LOCATION') api = Api(app, errors=errors) bcrypt = Bcrypt(app) jwt = JWTManager(app) app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb+srv://manas:[email protected]/moviedb?retryWrites=true&w=majority' } initialize_db(app) intitialize_routes(api)
import urllib.parse from flask import Flask from flask_restful import Api from database.db import initialize_db from resources.errors import errors from resources.routes import initialize_routes app = Flask(__name__) # flask app api = Api(app, errors=errors) # rest api username = urllib.parse.quote_plus('dbVishal') # database server username password = urllib.parse.quote_plus( 'yFlBhLiPVsnn0sDM') # database server password mongo_url = 'mongodb+srv://{0}:{1}@cluster0.b4a7f.mongodb.net/db_products?retryWrites=true&w=majority'.format( username, password) # database server url # configuration for db app.config['MONGODB_SETTINGS'] = {'host': mongo_url} initialize_db(app) # initializing database initialize_routes(api) # initializing api routes app.run(host="0.0.0.0", port=5001)