This commit is contained in:
hackrobot
2024-07-15 22:03:11 +08:00
parent 6fa209518e
commit ddad2bb1b2
2 changed files with 7 additions and 4 deletions

View File

@@ -14,12 +14,13 @@ app = FastAPI()
# 允许所有来源跨域访问(不推荐用于生产环境) # 允许所有来源跨域访问(不推荐用于生产环境)
origins = ["*"] origins = ["*"]
# 设置CORS跨域资源共享策略
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=origins, allow_origins=["*"], # 允许所有来源
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], # 允许所有HTTP方法 allow_methods=["*"], # 允许所有方法
allow_headers=["*"], # 允许所有HTTP allow_headers=["*"], # 允许所有请求
) )
# 依赖注入 # 依赖注入
def get_db(): def get_db():

4
run.py
View File

@@ -1,4 +1,6 @@
import uvicorn import uvicorn
if __name__ == "__main__": if __name__ == "__main__":
uvicorn.run("app.main:app", host="0.0.0.0", port=8700, reload=True) # uvicorn.run("app.main:app", host="0.0.0.0", port=8700, reload=True)
uvicorn.run("app.main:app", host="127.0.0.1", port=8700, reload=True)