加锁后效果如下:
如图docs/页面打开默认是茶壶,需加上定制参数才能正常访问 :
具体实现如下:
- 安装依赖包:
bash
pip install 'fastapi-cdn-host>=0.5.2' || pip install --upgrade git+ssh://git@github.com/waketzheng/fastapi-cdn-host
- 启用文档锁:
python
import fastapi_cdn_host
from fastapi import FastAPI
app = FastAPI(openapi_url="/api/v1/openapi.json")
fastapi_cdn_host.patch_docs(app, lock=fastapi_cdn_host.weekday_lock)
更多示例见:fastapi-cdn-host/tests/lock_docs/main.py at main · waketzheng/fastapi-cdn-host · GitHub