"""cPanel startup file.

Set "Application startup file" to  elitemart_app.py  and "Application entry point" to  application.
Do NOT name this file passenger_wsgi.py: cPanel writes its own passenger_wsgi.py that loads the startup
file, and a file of the same name would load itself forever (RecursionError).
"""
import os
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(HERE, "backend"))

from a2wsgi import ASGIMiddleware  # noqa: E402
from sqlalchemy.exc import IntegrityError  # noqa: E402

from app.main import app, setup_database  # noqa: E402

try:
    setup_database()  # makes the tables on first start; several workers may start together
except IntegrityError:
    pass  # another worker got there first

application = ASGIMiddleware(app)
