66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
import logging
|
|
import logging.config
|
|
from flask import Flask
|
|
from redis import Redis
|
|
|
|
from common.extensions import db, socketio, jwt, kms_client, cors, session
|
|
from config.logging_config import LOGGING
|
|
from eveai_chat.socket_handlers import chat_handler
|
|
from common.utils.cors_utils import create_cors_after_request
|
|
from common.utils.celery_utils import make_celery, init_celery
|
|
|
|
|
|
|
|
|
|
def create_app(config_file=None):
|
|
app = Flask(__name__)
|
|
|
|
if config_file is None:
|
|
app.config.from_object('config.config.DevConfig')
|
|
else:
|
|
app.config.from_object(config_file)
|
|
|
|
app.config['SESSION_KEY_PREFIX'] = 'eveai_chat_'
|
|
|
|
logging.config.dictConfig(LOGGING)
|
|
register_extensions(app)
|
|
|
|
app.celery = make_celery(app.name, app.config)
|
|
init_celery(app.celery, app)
|
|
|
|
# Register Blueprints
|
|
register_blueprints(app)
|
|
|
|
@app.route('/ping')
|
|
def ping():
|
|
return 'pong'
|
|
|
|
app.logger.info("EveAI Chat Server Started Successfully")
|
|
app.logger.info("-------------------------------------------------------------------------------------------------")
|
|
return app
|
|
|
|
|
|
def register_extensions(app):
|
|
db.init_app(app)
|
|
socketio.init_app(app,
|
|
message_queue=app.config.get('SOCKETIO_MESSAGE_QUEUE'),
|
|
cors_allowed_origins=app.config.get('SOCKETIO_CORS_ALLOWED_ORIGINS'),
|
|
async_mode=app.config.get('SOCKETIO_ASYNC_MODE'),
|
|
logger=app.config.get('SOCKETIO_LOGGER'),
|
|
engineio_logger=app.config.get('SOCKETIO_ENGINEIO_LOGGER'),
|
|
path='/socket.io'
|
|
)
|
|
jwt.init_app(app)
|
|
kms_client.init_app(app)
|
|
|
|
# Cors setup
|
|
cors.init_app(app, resources={r"/chat/*": {"origins": "*"}})
|
|
app.after_request(create_cors_after_request('/chat'))
|
|
|
|
session.init_app(app)
|
|
|
|
|
|
def register_blueprints(app):
|
|
from .views.chat_views import chat_bp
|
|
app.register_blueprint(chat_bp)
|