demo_site.py 508 B

1234567891011121314151617181920
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from fastapi import Request
  4. from common.exception import errors
  5. from core.conf import settings
  6. async def demo_site(request: Request):
  7. """演示站点"""
  8. method = request.method
  9. path = request.url.path
  10. if (
  11. settings.DEMO_MODE
  12. and method != 'GET'
  13. and method != 'OPTIONS'
  14. and (method, path) not in settings.DEMO_MODE_EXCLUDE
  15. ):
  16. raise errors.ForbiddenError(msg='演示环境下禁止执行此操作')