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 add_api_support(app): api = Api(app) from resources.routes import initialize_routes initialize_routes(api) return app
def create_app(): app = Flask(__name__) db.init_app(app) api.init_app(app) app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite3" app.config["SECRET_KEY"] = 'dev' from resources.routes import initialize_routes initialize_routes(api) return app
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 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)
from flask import (Flask, Response, redirect, render_template, request, session, url_for) from flask_restful import Api from resources.routes import initialize_routes dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) app = Flask(__name__, static_url_path="/static") app.secret_key = os.getenv("APP_SECRET") app.url_map.strict_slashes = False api = Api(app) initialize_routes(api) @app.route('/') def index(): return render_template("index.html") @app.route('/home') def home(): error = request.args.get('error') if session.get('email', None): return render_template("home.html", error=error) else: return redirect(url_for("login", error=error))
from flask import Flask from flask_restful import Api from database.db import initialize_db from resources.routes import initialize_routes from resources.movie_v1 import movies_v1 app = Flask(__name__) api = Api(app) app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb://localhost/flask-example-app' } initialize_db(app) app.register_blueprint(movies_v1) # using blueprint initialize_routes(api) # using flask_restful app.run()
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 flask import Flask from database.db import initialize_db from flask_restful import Api from flask_bcrypt import Bcrypt from resources.routes import initialize_routes #import jalur app = Flask(__name__) api = Api(app) Bcrypt = Bcrypt(app) app.config['MONGODB_SETTINGS'] = {'host': 'mongodb+srv://'} initialize_db(app) initialize_routes(api) #memanggil jalur app.run(debug=True, port=5001)
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)
from flask import Flask, jsonify from flask_cors import CORS from flask_marshmallow import Marshmallow from flask_restful import Api from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) # enable cors CORS(app) # import configuration app.config.from_pyfile('config/config.cfg') app.debug = True db = SQLAlchemy(app) ma = Marshmallow(app) from resources.routes import initialize_routes initialize_routes(Api(app))
from flask_bcrypt import Bcrypt from flask_jwt_extended import JWTManager from flask_restful import Api from flask_mail import Mail from database.db import initialize_db from resources.errors import errors app = Flask(__name__) app.config.from_envvar('ENV_FILE_LOCATION') mail = Mail(app) from resources.routes import initialize_routes v1 = Api(app, errors=errors) bcrypt = Bcrypt(app) jwt = JWTManager(app) app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb+srv://dbsuser:[email protected]/elektromaid?retryWrites=true&w=majority' } initialize_db(app) initialize_routes(v1) @app.route("/") def home_view(): return "<center><h1>Welcome to Elektromaid Api server</h1></center>"