Spaces:
Running
Running
| import os | |
| from litestar import Litestar, get, Request | |
| from litestar.response import Template | |
| from litestar.template.config import TemplateConfig | |
| from litestar.contrib.jinja import JinjaTemplateEngine | |
| from litestar.middleware.session.client_side import CookieBackendConfig | |
| from litestar.static_files import StaticFilesConfig | |
| from app.routes.dashboard import dashboard_home, reset_filters, force_refresh, export_csv | |
| from app.routes.auth import auth_login, auth_register, auth_logout, auth_reset_password | |
| from app.routes.settings import settings_page, settings_save, settings_endpoint_toggle | |
| from app.routes.profile import profile_page, change_password, delete_account | |
| from app.routes.watchlist import watchlist_toggle, watchlist_page | |
| from app.core.firebase import init_firebase | |
| from app.core.cache import start_public_autorefresh | |
| # Initializing Firebase Admin | |
| init_firebase() | |
| # Start background auto-refresh for the public (keyless) endpoint | |
| start_public_autorefresh() | |
| # Secure session config | |
| _secret = os.getenv("SESSION_SECRET", "placeholder-32-chars-long-string-!!").encode() | |
| session_config = CookieBackendConfig(secret=_secret) | |
| async def index(request: Request) -> Template: | |
| uid = request.session.get("uid") | |
| email = request.session.get("email") | |
| user_context = {"uid": uid, "email": email} if uid else None | |
| return Template(template_name="index.html", context={"user": user_context}) | |
| app = Litestar( | |
| route_handlers=[ | |
| index, | |
| dashboard_home, | |
| reset_filters, | |
| force_refresh, | |
| export_csv, | |
| auth_login, | |
| auth_register, | |
| auth_logout, | |
| auth_reset_password, | |
| settings_page, | |
| settings_save, | |
| settings_endpoint_toggle, | |
| profile_page, | |
| change_password, | |
| delete_account, | |
| watchlist_toggle, | |
| watchlist_page, | |
| ], | |
| template_config=TemplateConfig( | |
| directory="app/templates", | |
| engine=JinjaTemplateEngine, | |
| ), | |
| static_files_config=[ | |
| StaticFilesConfig( | |
| directories=["app/static"], | |
| path="/static", | |
| html_mode=False, | |
| ) | |
| ], | |
| middleware=[session_config.middleware], | |
| ) | |