Beispiel #1
0
def create_app(
    debug=None,
    local=None,
    secret_key=None,
    async_mode="gevent",
    config_filename=None,
    section=None,
    new_hire_section=None,
):
    app = Flask(__name__, instance_path="/var/cyhy/web")
    gunicorn_logger = logging.getLogger("gunicorn.error")
    app.logger.handlers = gunicorn_logger.handlers
    app.logger.setLevel(gunicorn_logger.level)
    cache.init_app(app)

    # Manually setting cors_allowed_origins to allow all due to a change in July
    # (2019) per https://github.com/miguelgrinberg/python-engineio/commit/7548f704a0a3000b7ac8a6c88796c4ae58aa9c37
    # Previously the default resulted in similar behavior, but now the default
    # is to use the host address in the request. The configuration of our
    # application does not work with this change so I am forcing an equivalent to
    # the old behavior. We may want to look into providing CORS for websocket
    # connections in the future.
    socketio.init_app(app, async_mode=async_mode, cors_allowed_origins="*")

    install_secret_key(app, secret_key)
    register_blueprints(app)
    using_yaml = str(config_filename).lower().endswith((".yml", ".yaml"))
    app.db = database.db_from_config(section,
                                     config_filename=config_filename,
                                     yaml=using_yaml)
    # TODO add exception handler for no new_hire_section
    app.new_hire_db = database.db_from_config(new_hire_section,
                                              config_filename=config_filename,
                                              yaml=using_yaml)
    app.logger.debug(app.new_hire_db)
    app.logger.debug(app.db)
    start_scheduler(app)
    # TODO set origins via environment variables
    origins = [".*[\.]?data\.ncats\.dhs\.gov"]
    if local:
        origins.append("^.*\/\/localhost(:[0-9]+)?$")
    print origins
    CORS(app, resources={r"\/.*": {"origins": origins}})
    # import IPython; IPython.embed() #<<< BREAKPOINT >>>
    # app.run(host='::', debug, threaded=True)
    app.config["DEBUG"] = debug

    return app
Beispiel #2
0
from layout import generate_layout, register_callbacks
from common import cache

os.environ['DASH_PRUNE_ERRORS'] = 'False'
os.environ['DASH_SILENCE_ROUTES_LOGGING'] = 'False'

app = dash.Dash(__name__, suppress_callback_exceptions=True)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True

server = app.server
with server.app_context():
    server.config.from_object('common.settings')

    cache.init_app(server)

    sess = Session()
    sess.init_app(server)

    babel = Babel(server)

app.layout = generate_layout(app)
register_callbacks(app)

if __name__ == '__main__':
    # Write the process pid to a file for easier profiling with py-spy
    with open('.ghgdash.pid', 'w') as pid_file:
        pid_file.write(str(os.getpid()))
    app.run_server(debug=True)
Beispiel #3
0
from flask import Flask

from common import cache
from index import index_page
from search import search_page
from status import status_page
from subreddits import subreddits_page
from upload import upload_page
from video_thumbs import video_thumbs

app = Flask(__name__)
cache.init_app(app)
app.register_blueprint(subreddits_page)
app.register_blueprint(status_page)
app.register_blueprint(index_page)
app.register_blueprint(search_page)
app.register_blueprint(upload_page)
app.register_blueprint(video_thumbs)

if __name__ == '__main__':
    app.run(port=3080)