fix(storefront): send no-cache headers on dynamic CMS and layout endpoints

This commit is contained in:
iFixKart Dev 2026-11-17 19:47:00 +05:30
parent 7c81c21f2d
commit 60b9cef189
2 changed files with 14 additions and 7 deletions

View file

@ -3,7 +3,7 @@
@purpose Read-only public endpoints for footer info, store settings, mega menu, catalog filters, @purpose Read-only public endpoints for footer info, store settings, mega menu, catalog filters,
trust badges, blog posts, and product reviews — all backed by StorefrontCmsService. trust badges, blog posts, and product reviews — all backed by StorefrontCmsService.
""" """
from fastapi import APIRouter, Depends, Query from fastapi import APIRouter, Depends, Query, Response
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
@ -18,21 +18,24 @@ router = APIRouter(prefix="/api/v1/storefront", tags=["Storefront Dynamic Servic
@router.get("/footer-info") @router.get("/footer-info")
def get_footer_info(db: Session = Depends(get_db)) -> Any: def get_footer_info(response: Response, db: Session = Depends(get_db)) -> Any:
"""Returns dynamic footer contact info, social links, navigation columns, and payment icons.""" """Returns dynamic footer contact info, social links, navigation columns, and payment icons."""
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
svc = StorefrontCmsService(db) svc = StorefrontCmsService(db)
return svc.get_footer_info() return svc.get_footer_info()
@router.get("/settings") @router.get("/settings")
def get_storefront_settings(db: Session = Depends(get_db)) -> Any: def get_storefront_settings(response: Response, db: Session = Depends(get_db)) -> Any:
"""Returns store branding settings (logo, wordmark, support phone, advance_percent, etc.).""" """Returns store branding settings (logo, wordmark, support phone, advance_percent, etc.)."""
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
svc = StorefrontCmsService(db) svc = StorefrontCmsService(db)
return svc.get_settings() return svc.get_settings()
@router.get("/mega-menu") @router.get("/mega-menu")
def get_mega_menu( def get_mega_menu(
response: Response,
nav_key: Optional[str] = Query(None, pattern="^(shop|deals|products)$"), nav_key: Optional[str] = Query(None, pattern="^(shop|deals|products)$"),
db: Session = Depends(get_db), db: Session = Depends(get_db),
) -> Any: ) -> Any:
@ -41,13 +44,15 @@ def get_mega_menu(
If nav_key is supplied returns single menu config. If nav_key is supplied returns single menu config.
If omitted returns all three (shop, deals, products) in one payload. If omitted returns all three (shop, deals, products) in one payload.
""" """
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
svc = StorefrontCmsService(db) svc = StorefrontCmsService(db)
return svc.get_mega_menu(nav_key) return svc.get_mega_menu(nav_key)
@router.get("/catalog-filters") @router.get("/catalog-filters")
def get_catalog_filters(db: Session = Depends(get_db)) -> Any: def get_catalog_filters(response: Response, db: Session = Depends(get_db)) -> Any:
"""Returns highlight filter tabs and price range buckets for the shop catalog page.""" """Returns highlight filter tabs and price range buckets for the shop catalog page."""
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
svc = StorefrontCmsService(db) svc = StorefrontCmsService(db)
return svc.get_catalog_filters() return svc.get_catalog_filters()
@ -112,8 +117,9 @@ def get_blog_posts() -> List[Dict[str, Any]]:
@router.get("/banners") @router.get("/banners")
def get_storefront_banners(db: Session = Depends(get_db)) -> List[Dict[str, Any]]: def get_storefront_banners(response: Response, db: Session = Depends(get_db)) -> List[Dict[str, Any]]:
"""Returns hero banners for the storefront homepage (BUG-04 fix).""" """Returns hero banners for the storefront homepage (BUG-04 fix)."""
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
svc = StorefrontCmsService(db) svc = StorefrontCmsService(db)
banners = svc.get_content_by_region(page="home", region="hero", content_type="hero_banner") banners = svc.get_content_by_region(page="home", region="hero", content_type="hero_banner")
if banners: if banners:

View file

@ -2,7 +2,7 @@
@router Public Storefront Router (Backend/app/api/v1/routers/storefront.py) @router Public Storefront Router (Backend/app/api/v1/routers/storefront.py)
@purpose Read-only public endpoints for layout widgets, reviews, and settings powered by StorefrontService. @purpose Read-only public endpoints for layout widgets, reviews, and settings powered by StorefrontService.
""" """
from fastapi import APIRouter, Depends, Query, HTTPException, status, Request from fastapi import APIRouter, Depends, Query, HTTPException, status, Request, Response
from sqlalchemy.orm import Session, selectinload from sqlalchemy.orm import Session, selectinload
from sqlalchemy import select from sqlalchemy import select
from typing import List, Dict, Any, Optional from typing import List, Dict, Any, Optional
@ -182,10 +182,11 @@ def live_search(
@router.get("/layout/{page}") @router.get("/layout/{page}")
def get_storefront_layout(page: str, region: Optional[str] = Query(None), db: Session = Depends(get_db)): def get_storefront_layout(page: str, response: Response, region: Optional[str] = Query(None), db: Session = Depends(get_db)):
""" """
Returns active storefront layout widgets ordered by display_order. Returns active storefront layout widgets ordered by display_order.
""" """
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
service = StorefrontService(db) service = StorefrontService(db)
return service.get_layout(page, region) return service.get_layout(page, region)