"""
passenger_wsgi.py — cPanel Passenger entry point for the Scheinman Flask app.

Passenger with PassengerBaseURI "/scheinman" may or may not strip the prefix
from PATH_INFO depending on server config. This wrapper strips it when present
so Flask always receives the correct path regardless.
"""
import sys
import os

_here = os.path.dirname(os.path.abspath(__file__))
if _here not in sys.path:
    sys.path.insert(0, _here)

from app import app as flask_app  # noqa: E402

_PREFIX = '/scheinman'

def application(environ, start_response):
    path = environ.get('PATH_INFO', '')
    if path.startswith(_PREFIX):
        environ['SCRIPT_NAME'] = _PREFIX
        environ['PATH_INFO'] = path[len(_PREFIX):] or '/'
    return flask_app(environ, start_response)
