"""Loopback-only preview with an exact allowlist of existing store frontend assets."""
from pathlib import Path
from http.server import ThreadingHTTPServer,SimpleHTTPRequestHandler
from urllib.parse import urlsplit,unquote
import os
R=Path(__file__).resolve().parent
repo=R.parents[1]
front=Path(os.environ.get('STORE_FRONTEND',str(repo.parent/'zhctproject/store/public/static')))
base=repo/'work_ai_app/2026-09-08-food-movement-calendar'
assets={'exceljs.js':Path('/Users/jack/.codex/ruflo-runtime/diet-photo-20260914/deps/node_modules/exceljs/dist/exceljs.min.js'),'jszip.js':Path(os.environ.get('CODEX_NODE_MODULES','/Users/jack/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules'))/'jszip/dist/jszip.min.js','vue.js':front/'node_modules/vue/dist/vue.js','element.js':front/'node_modules/element-ui/lib/index.js','element.css':front/'node_modules/element-ui/lib/theme-chalk/index.css','echarts.js':front/'node_modules/echarts/dist/echarts.min.js','logo.png':front/'static/cptNewLogoH.png','fonts/element-icons.woff':front/'node_modules/element-ui/lib/theme-chalk/fonts/element-icons.woff','fonts/element-icons.ttf':front/'node_modules/element-ui/lib/theme-chalk/fonts/element-icons.ttf'}
class Handler(SimpleHTTPRequestHandler):
 def __init__(self,*a,**kw):super().__init__(*a,directory=str(R),**kw)
 def translate_path(self,path):
  path=unquote(urlsplit(path).path)
  if path.startswith('/runtime/'):return str(assets.get(path[9:],R/'__missing__'))
  if path.startswith('/task/'):
   target=(base/'diet-weight-study'/path[6:]).resolve()
   return str(target if target.is_relative_to(base) else R/'__missing__')
  return super().translate_path(path)
 def end_headers(self):self.send_header('Cache-Control','no-store');super().end_headers()
if __name__=='__main__':
 for name,path in assets.items():
  if not path.exists():raise SystemExit('Missing local runtime asset: '+name)
 ThreadingHTTPServer(('127.0.0.1',8790),Handler).serve_forever()
