rewrite
This commit is contained in:
56
app.py
56
app.py
@@ -12,7 +12,7 @@ from flask import Flask, render_template, redirect, url_for, session
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
from config.settings import *
|
||||
from database import db, migrate # ✅ NIE importuj init_db tutaj!
|
||||
from database import db, migrate, init_db
|
||||
from routes.main_routes import main_bp
|
||||
from routes.edit_routes import edit_bp
|
||||
from routes.auth_routes import auth_bp
|
||||
@@ -60,7 +60,6 @@ app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
||||
print("[APP] Initializing database...", flush=True)
|
||||
db.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
# ❌ USUŃ TĘ LINIĘ: init_db(app)
|
||||
print("[APP] Database initialized", flush=True)
|
||||
|
||||
|
||||
@@ -87,23 +86,26 @@ private_key_path = None
|
||||
ssl_context = None
|
||||
|
||||
try:
|
||||
config_ssl = configparser.ConfigParser()
|
||||
config_ssl.read(SSL_INI)
|
||||
|
||||
if config_ssl.has_section('ssl'):
|
||||
certificate_path = config_ssl.get('ssl', 'certificate_path')
|
||||
private_key_path = config_ssl.get('ssl', 'private_key_path')
|
||||
if os.path.exists(SSL_INI):
|
||||
config_ssl = configparser.ConfigParser()
|
||||
config_ssl.read(SSL_INI)
|
||||
|
||||
if os.path.exists(certificate_path) and os.path.exists(private_key_path):
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
|
||||
ssl_context.load_cert_chain(certfile=certificate_path, keyfile=private_key_path)
|
||||
print("[APP] SSL context loaded successfully", flush=True)
|
||||
if config_ssl.has_section('ssl'):
|
||||
certificate_path = config_ssl.get('ssl', 'certificate_path')
|
||||
private_key_path = config_ssl.get('ssl', 'private_key_path')
|
||||
|
||||
if os.path.exists(certificate_path) and os.path.exists(private_key_path):
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
|
||||
ssl_context.load_cert_chain(certfile=certificate_path, keyfile=private_key_path)
|
||||
print("[APP] SSL context loaded successfully", flush=True)
|
||||
else:
|
||||
print(f"[APP] SSL certificate files not found", flush=True)
|
||||
print(f" Certificate: {certificate_path}", flush=True)
|
||||
print(f" Private Key: {private_key_path}", flush=True)
|
||||
else:
|
||||
print(f"[APP] SSL certificate files not found", flush=True)
|
||||
print(f" Certificate: {certificate_path}", flush=True)
|
||||
print(f" Private Key: {private_key_path}", flush=True)
|
||||
print(f"[APP] No [ssl] section in {SSL_INI}", flush=True)
|
||||
else:
|
||||
print(f"[APP] No [ssl] section in {SSL_INI}", flush=True)
|
||||
print(f"[APP] No SSL config file found: {SSL_INI}", flush=True)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[APP] SSL warning (non-critical): {e}", flush=True)
|
||||
@@ -182,8 +184,6 @@ def make_shell_context():
|
||||
}
|
||||
|
||||
|
||||
# ===== APPLICATION CONTEXT =====
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
"""Run before each request"""
|
||||
@@ -201,10 +201,8 @@ def after_request(response):
|
||||
@app.cli.command()
|
||||
def init_db_cli():
|
||||
"""Initialize database"""
|
||||
with app.app_context():
|
||||
from database import init_db
|
||||
init_db(app)
|
||||
print("[CLI] Database initialized successfully")
|
||||
init_db(app)
|
||||
print("[CLI] Database initialized successfully", flush=True)
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
@@ -229,16 +227,6 @@ def create_admin():
|
||||
print(f"[CLI] Admin user '{username}' created successfully")
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def import_config():
|
||||
"""Import existing haproxy.cfg to database"""
|
||||
from database.migration import parse_existing_haproxy_config
|
||||
|
||||
config_path = HAPROXY_CONFIG_PATH
|
||||
count = parse_existing_haproxy_config(config_path)
|
||||
print(f"[CLI] Successfully imported {count} vhosts from {config_path}")
|
||||
|
||||
|
||||
# ===== MAIN ENTRY POINT =====
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -253,9 +241,7 @@ if __name__ == '__main__':
|
||||
print(f"[APP] Running on: https://[::]:5000 (IPv6)", flush=True)
|
||||
|
||||
# Initialize database before running
|
||||
with app.app_context():
|
||||
from database import init_db
|
||||
init_db(app)
|
||||
init_db(app)
|
||||
|
||||
app.run(
|
||||
host='::',
|
||||
|
||||
Reference in New Issue
Block a user