fix CORSMiddleware
This commit is contained in:
parent
7248ce3105
commit
8b4a44c8d4
@ -11,6 +11,8 @@ class Settings(BaseSettings):
|
||||
API_V1_STR: str = "/api/v1"
|
||||
# 密钥
|
||||
SECRET_KEY: str = secrets.token_urlsafe(32)
|
||||
# 允许的域名
|
||||
ALLOWED_HOSTS: list = ["*"]
|
||||
# TOKEN过期时间
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
||||
# 时区
|
||||
|
10
app/main.py
10
app/main.py
@ -1,5 +1,6 @@
|
||||
import uvicorn as uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from uvicorn import Config
|
||||
|
||||
from app.api.apiv1 import api_router
|
||||
@ -17,6 +18,15 @@ from app.scheduler import Scheduler
|
||||
App = FastAPI(title=settings.PROJECT_NAME,
|
||||
openapi_url=f"{settings.API_V1_STR}/openapi.json")
|
||||
|
||||
# 跨域
|
||||
App.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.ALLOWED_HOSTS,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# API路由
|
||||
App.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user