mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-27 07:27:03 +01:00
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
from config import config
|
|
from .database import db
|
|
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
|
|
from flask_sslify import SSLify
|
|
from titanembeds.utils import rate_limiter, discord_api, bot_alive, socketio
|
|
from .blueprints import api, user, admin, embed, gateway
|
|
import os
|
|
from titanembeds.database import get_administrators_list
|
|
|
|
try:
|
|
import uwsgi
|
|
from gevent import monkey
|
|
monkey.patch_all()
|
|
except:
|
|
if config.get("websockets-mode", None) == "eventlet":
|
|
import eventlet
|
|
eventlet.monkey_patch()
|
|
elif config.get("websockets-mode", None) == "gevent":
|
|
from gevent import monkey
|
|
monkey.patch_all()
|
|
|
|
os.chdir(config['app-location'])
|
|
app = Flask(__name__, static_folder="static")
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = config['database-uri']
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Suppress the warning/no need this on for now.
|
|
app.config['RATELIMIT_HEADERS_ENABLED'] = True
|
|
app.config['SQLALCHEMY_POOL_RECYCLE'] = 250
|
|
app.config['RATELIMIT_STORAGE_URL'] = 'keyvalprops://'
|
|
app.secret_key = config['app-secret']
|
|
|
|
db.init_app(app)
|
|
rate_limiter.init_app(app)
|
|
sslify = SSLify(app, permanent=True)
|
|
socketio.init_app(app, message_queue=config["redis-uri"], path='gateway', async_mode=config.get("websockets-mode", None))
|
|
|
|
app.register_blueprint(api.api, url_prefix="/api", template_folder="/templates")
|
|
app.register_blueprint(admin.admin, url_prefix="/admin", template_folder="/templates")
|
|
app.register_blueprint(user.user, url_prefix="/user", template_folder="/templates")
|
|
app.register_blueprint(embed.embed, url_prefix="/embed", template_folder="/templates")
|
|
socketio.on_namespace(gateway.Gateway('/gateway'))
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return render_template("index.html.j2")
|
|
|
|
@app.route("/about")
|
|
def about():
|
|
return render_template("about.html.j2")
|
|
|
|
@app.before_request
|
|
def before_request():
|
|
discord_api.init_discordrest()
|
|
|
|
@app.context_processor
|
|
def context_processor():
|
|
bot_status = bot_alive()
|
|
return {"bot_status": bot_status, "devs": get_administrators_list()} |