"""WSGI entry point for production deployment.""" from app import app class ReverseProxied: """WSGI middleware that reads X-Script-Name header from reverse proxy and sets SCRIPT_NAME so Flask's url_for() generates correct prefixed URLs. The reverse proxy (nginx/Apache) should set this header to the subpath prefix, e.g. /hm-ai-qc-report. """ def __init__(self, app): self.app = app def __call__(self, environ, start_response): script_name = environ.get('HTTP_X_SCRIPT_NAME', '') if script_name: environ['SCRIPT_NAME'] = script_name # Strip the prefix from PATH_INFO if it's still there path_info = environ.get('PATH_INFO', '') if path_info.startswith(script_name): environ['PATH_INFO'] = path_info[len(script_name):] return self.app(environ, start_response) application = ReverseProxied(app) if __name__ == "__main__": app.run()