def initialize_app(flask_app): configure_app(flask_app) db.init_app(flask_app) api.init_app(flask_app) with app.app_context(): on_app_startup()
def create_app(config_name): app = Flask(__name__) # setup configs app.config.from_object(configs[config_name]) # init modules cors.init_app(app) db.init_app(app) jwt.init_app(app) api.init_app(app) # routes #CORS # redirect app.add_url_rule('/scans/<int:scan_rel_id>/vuln', endpoint='VulnsList') # list vulns found in a scan @app.before_request def detect_user_language(): print request.data print request.headers return app
def create_app(config_name): app=Flask(__name__) app.config.from_object(config_by_name[config_name]) db.init_app(app) api.init_app(app) return app
def initialize_app(flask_app): blueprint = Blueprint('api', __name__, url_prefix='/api') api.init_app(blueprint) # register blueprints # flask_app.register_blueprint(views.customers) flask_app.register_blueprint(blueprint)
def create_app(configuration): app = Flask(__name__) app.config.from_object(config_by_name[configuration]) db.init_app(app) api.init_app(app) CORS(app) return app
def create_app(test_config=None): app = Flask(__name__, static_url_path='', static_folder='static') app.config["TEST_ENV_VARIABLE"] = os.environ.get('TEST_ENV_VARIABLE', 'not set') api.init_app(app) # app.register_blueprint(home_api, url_prefix='/api') return app
def create_app(name, settings_override=None): app = Flask(name) if (settings_override is None): database_uri = os.environ.get("DATABASE_URL", "postgres://postgres@localhost:5432/booklibrary") app.config['SQLALCHEMY_DATABASE_URI']=database_uri else: app.config.update(settings_override) #app.config['TESTING'] = True #app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://postgres@localhost:5432/booklibrary' from apis import api api.init_app(app) return app
def main(): parser = argparse.ArgumentParser(description="Imaging Server Help") parser.add_argument( '-H', '--host', metavar='hostname', help= 'The hostname to publish the server on. For Docker, this should be 0.0.0.0' ) parser.add_argument( '-g', action='store_true', help= "By default geolocation will run in its own thread when the server starts. If you dont want that, you can turn it off with this flag." ) args = parser.parse_args() hostname = "0.0.0.0" if args.host is not None: hostname = args.host if args.g is not None and args.g: print("Starting with NO geolocation") app = Flask(__name__) api.init_app(app) #app.start(debug=True, host=hostname) global server server = ServerThread(app, hostname) if not args.g: global geolocation geolocation = GeolocationThread() # now that our server thread is setup, we can configure sigint to properly close it signal.signal(signal.SIGINT, signal_handler) server.start() print("Server Started!") print(" Host:: {}:{}".format(hostname, 5000)) if not args.g: geolocation.start() print("Geolocation Started!")
def create_app() -> Flask: """ Function that creates a Flask application. App configuration is set here. Create application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/. Args: debug: debug mode enabled or not. Returns: app: a Flask app already configured to run. """ app = Flask(__name__) app.config.from_pyfile('config.py') api.init_app(app) return app
def initialize_app(flask_app: Flask) -> None: from models import db, db_url from apis import api from auth import auth from utils.env_loader import DIR_KUBE_CONFIG, config if not os.path.isdir(DIR_KUBE_CONFIG): os.mkdir(DIR_KUBE_CONFIG) configure_app(flask_app, db_url()) api.init_app(flask_app) if 'auth' in config: auth.init_app(flask_app, api) CORS(flask_app) db.init_app(flask_app) db.create_all(app=flask_app)
def create_app(): app = Flask(__name__, instance_relative_config=True) app.config.from_pyfile('defaults.py', silent=True) app.name = app.config['TITLE'] app.url_map.strict_slashes = False from apis import api api.init_app(app) api.title = app.config['TITLE'] api.description = app.config['DESCRIPTION'] api.version = app.config['VERSION'] api.doc = app.config['DOC_PATH'] api.contact = app.config['CONTACT'] setup_request_handlers(app) setup_exception_handlers(app, api) return app
def create_app(): app = Flask(__name__) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/richText' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config['UPLOADED_PHOTO_DEST'] = os.path.dirname( os.path.abspath(__file__)) + '/file_uploads' app.config['UPLOADED_PHOTO_ALLOW'] = IMAGES api.init_app(app) db.init_app(app) configure_uploads(app, photo_test) @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS') return response migrate = Migrate(app, db) return app
def create_app(): """ Create flask app """ app = Flask(__name__) # CORS(app) app.config['MONGODB_SETTINGS'] = { 'db': settings.MONGODB_SETTINGS_DB, 'username': settings.MONGODB_SETTINGS_USERNAME, 'password': settings.MONGODB_SETTINGS_PASSWORD, 'host': settings.MONGODB_SETTINGS_HOST, 'port': settings.MONGODB_SETTINGS_PORT } app.config['PORT'] = settings.PORT # app.config['ERROR_404_HELP'] = False # app.config['DEBUG'] = True db.init_app(app) api.init_app(app) create_default_admin(app) return app
from flask import Flask from apis import api app = Flask(__name__) # app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True api.init_app(app) if __name__ == '__main__': app.run(port=8000)
from flask_jwt_extended import JWTManager, jwt_required, jwt_refresh_token_required, get_jwt_identity, get_raw_jwt import logging LOGGINGFORMAT = '%(asctime)-15s %(levelname)-8s %(name)-8s %(message)s' logging.basicConfig(level=logging.DEBUG, format=LOGGINGFORMAT, datefmt='%d-%b-%y %H:%M:%S') mapp = Flask(__name__) mapp.secret_key = 'super secret key' mapp.config['PROPAGATE_EXCEPTIONS'] = True mapp.config['JWT_SECRET_KEY'] = 'test-123' mapp.config['JWT_DECODE_AUDIENCE'] = 'testapp' mapp.config['JWT_ENCODE_AUDIENCE'] = 'testapp' api.init_app(mapp) jwt = JWTManager(mapp) #register error handlers (inbuilt) jwt._set_error_handler_callbacks(api) #host multiple instances d = PathInfoDispatcher({'/product-api': mapp}) server = WSGIServer(('0.0.0.0', 8083), d) #docker run -d -p 8088:8088 -t nginx #start web server try: server.start() except KeyboardInterrupt: server.stop()
from flask import Flask from apis import api flask_app = Flask(__name__) api.init_app(flask_app) flask_app.run(host="0.0.0.0", port=8080, debug=True)