在 github pages 的网页里调用自己的 fastapi 后端,需要单独设置一下 CORS 。目前后端使用下面的代码是能正常工作的
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*", ],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
但是将*号改成自己的网址的话却会显示请求被 cors 拒绝,搞不太清楚哪步出了问题
allow_origins=["https://my.github.io", ] # 改成这样以后就访问不了了
是因为 cors 只支持 https://*.github.io 这种写法吗?还是后端反向代理的原因,请求经过 nginx 反向代理到 fastapi 以后 origin 变了?