2022-12-31 04:14:08 +00:00
|
|
|
from sys import platform
|
2022-01-16 18:22:00 +00:00
|
|
|
from app import create_app
|
|
|
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
|
|
@app.shell_context_processor
|
|
|
|
def make_shell_context():
|
|
|
|
"""Extend the Flask shell context."""
|
|
|
|
return {'app': app}
|
|
|
|
|
2022-12-31 04:14:08 +00:00
|
|
|
running_directly = __name__ == "__main__"
|
|
|
|
running_under_gunicorn = not running_directly and 'gunicorn' in __name__ and 'linux' in platform
|
2022-01-16 18:22:00 +00:00
|
|
|
|
2022-12-31 04:14:08 +00:00
|
|
|
# Configure development running
|
|
|
|
if running_directly:
|
2022-01-16 18:22:00 +00:00
|
|
|
with app.app_context():
|
|
|
|
app.run(host='0.0.0.0')
|
2022-12-31 04:14:08 +00:00
|
|
|
|
|
|
|
# Configure production running
|
|
|
|
if running_under_gunicorn:
|
2022-02-16 19:33:12 +00:00
|
|
|
import logging
|
2022-02-16 19:39:55 +00:00
|
|
|
from logging.handlers import RotatingFileHandler
|
2022-02-16 19:33:12 +00:00
|
|
|
gunicorn_logger = logging.getLogger('gunicorn.error')
|
|
|
|
app.logger.handlers = gunicorn_logger.handlers
|
2022-12-17 04:50:43 +00:00
|
|
|
file_handler = RotatingFileHandler('logs/nexus_dashboard.log', maxBytes=1024 * 1024 * 100, backupCount=20)
|
2022-02-16 19:33:12 +00:00
|
|
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
|
|
|
file_handler.setFormatter(formatter)
|
|
|
|
app.logger.addHandler(file_handler)
|
|
|
|
app.logger.setLevel(gunicorn_logger.level)
|
2022-12-31 04:14:08 +00:00
|
|
|
|
|
|
|
# Error out if nothing has been setup
|
|
|
|
if not running_directly and not running_under_gunicorn:
|
|
|
|
raise RuntimeError('Unsupported WSGI server')
|