84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
import sys
|
|
import os
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
|
|
from flask import Flask, redirect, request, session, url_for
|
|
from web.config import Config
|
|
from web.database import close_dbs, initialize_web_db
|
|
from web.auth import get_csrf_token
|
|
|
|
|
|
def create_app(config_object=Config):
|
|
app = Flask(__name__)
|
|
app.config.from_object(config_object)
|
|
|
|
initialize_web_db()
|
|
from web.services.roster_version_service import RosterVersionService
|
|
RosterVersionService.ensure_initial_version()
|
|
app.teardown_appcontext(close_dbs)
|
|
app.jinja_env.globals['csrf_token'] = get_csrf_token
|
|
|
|
@app.context_processor
|
|
def inject_brand():
|
|
return {
|
|
'brand': {
|
|
'primary': app.config['BRAND_PRIMARY'],
|
|
'aliases': app.config['BRAND_ALIASES'],
|
|
'signature': app.config['BRAND_SIGNATURE'],
|
|
}
|
|
}
|
|
|
|
@app.before_request
|
|
def require_private_access():
|
|
if app.config['SITE_VISIBILITY'] != 'private':
|
|
return None
|
|
endpoint = request.endpoint or ''
|
|
if (
|
|
endpoint == 'static'
|
|
or endpoint == 'main.healthz'
|
|
or endpoint.startswith('access.')
|
|
or endpoint.startswith('admin.')
|
|
or session.get('viewer_access')
|
|
or session.get('is_admin')
|
|
):
|
|
return None
|
|
return redirect(url_for(
|
|
'access.login',
|
|
next=request.full_path if request.method == 'GET' else None,
|
|
))
|
|
|
|
from web.routes import (
|
|
admin,
|
|
access,
|
|
awards,
|
|
discover,
|
|
main,
|
|
matches,
|
|
opponents,
|
|
players,
|
|
reports,
|
|
tactics,
|
|
teams,
|
|
wiki,
|
|
)
|
|
app.register_blueprint(main.bp)
|
|
app.register_blueprint(access.bp)
|
|
app.register_blueprint(matches.bp)
|
|
app.register_blueprint(players.bp)
|
|
app.register_blueprint(teams.bp)
|
|
app.register_blueprint(tactics.bp)
|
|
app.register_blueprint(admin.bp)
|
|
app.register_blueprint(wiki.bp)
|
|
app.register_blueprint(opponents.bp)
|
|
app.register_blueprint(reports.bp)
|
|
app.register_blueprint(awards.bp)
|
|
app.register_blueprint(discover.bp)
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(debug=True, port=5000)
|