# app/modules/hosting/routes/pages/public.py """ Hosting Public Page Routes. POC site preview via signed URL redirect to the storefront. The StorefrontAccessMiddleware validates the preview token and allows rendering without an active subscription. """ from fastapi import APIRouter, Depends, Path, Query from fastapi.responses import HTMLResponse, RedirectResponse from sqlalchemy.orm import Session from app.core.database import get_db from app.core.preview_token import create_preview_token router = APIRouter() @router.get( "/hosting/sites/{site_id}/preview", include_in_schema=False, ) async def poc_site_viewer( site_id: int = Path(..., description="Hosted Site ID"), page: str = Query("homepage", description="Page slug to preview"), db: Session = Depends(get_db), ): """Redirect to storefront with signed preview token. Generates a time-limited JWT and redirects to the store's storefront URL. The StorefrontAccessMiddleware validates the token and bypasses the subscription check. """ from app.modules.hosting.models import HostedSite, HostedSiteStatus site = db.query(HostedSite).filter(HostedSite.id == site_id).first() if not site or site.status not in ( HostedSiteStatus.POC_READY, HostedSiteStatus.PROPOSAL_SENT, HostedSiteStatus.ACCEPTED, ): return HTMLResponse(content="