gateway_contract.py 814 B

123456789101112131415161718192021
  1. # -*- coding: utf-8 -*-
  2. r"""统一入口与路由表接口(**组件接入点:Nginx**)。
  3. 现在:Python 网关 `scripts/guanlan_gateway.py`(前缀改写 + data-abs 豁免 + 静态件)。
  4. 目标:Nginx 承担反代与静态托管,网关退化为**路由表**(本接口即路由表的读写面)。
  5. P0 只立契约,无实现(默认仍是 Python 网关)。
  6. """
  7. from __future__ import annotations
  8. from abc import ABC, abstractmethod
  9. class Gateway(ABC):
  10. @abstractmethod
  11. def routes(self) -> list[dict]:
  12. """→ [{prefix, upstream_port, name}](现由 gateway 的 ROUTES 提供)。"""
  13. @abstractmethod
  14. def rewrite(self, html: bytes, *, component: str) -> bytes:
  15. """组件前缀改写(`data-abs="1"` 链接豁免的规则保持)。"""