65 lines
2.0 KiB
Python
65 lines
2.0 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
|
|
|
|
|
|
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)
|
|
|
|
logging.config.dictConfig(LOGGING)
|
|
register_extensions(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 setup
|
|
# redis_config = app.config['SESSION_REDIS']
|
|
# redis_client = Redis(host=redis_config['host'],
|
|
# port=redis_config['port'],
|
|
# db=redis_config['db'],
|
|
# password=redis_config['password']
|
|
# )
|
|
session.init_app(app)
|
|
|
|
|
|
def register_blueprints(app):
|
|
from .views.chat_views import chat_bp
|
|
app.register_blueprint(chat_bp)
|