runtime_config.py 924 B

12345678910111213141516171819202122232425262728
  1. """运行时只读配置接口。
  2. 向前端暴露由后端 ``.env`` / 启动器决定的非敏感配置项,
  3. 让前端可以根据后端策略切换实现(如 PDF 预览引擎),
  4. 而不必把每个环境变量都硬编码进打包产物。
  5. """
  6. from __future__ import annotations
  7. from flask import current_app
  8. from dms.api.v1.blueprint import api_v1
  9. from dms.common.response import success_response
  10. @api_v1.get("/config/runtime")
  11. def get_runtime_config():
  12. pdf_viewer_engine = current_app.config.get(
  13. "DMS_PDF_VIEWER_ENGINE", "iframe"
  14. )
  15. if pdf_viewer_engine not in {"iframe", "pdfjs"}:
  16. pdf_viewer_engine = "iframe"
  17. response, status = success_response(
  18. {"pdfViewerEngine": pdf_viewer_engine}
  19. )
  20. # 该接口仅暴露非敏感开关,允许浏览器缓存以减少首屏请求。
  21. response.headers["Cache-Control"] = "public, max-age=60"
  22. return response, status