CORS最后一commit
This commit is contained in:
parent
298830cd1e
commit
b2fbe2cf4a
@ -43,7 +43,14 @@ async def login(response: Response, user_data: dict, session: SessionDep):
|
|||||||
token = create_access_token(data={"id": user.id, "role": user.role, "tanant_id": user.tenant.id})
|
token = create_access_token(data={"id": user.id, "role": user.role, "tanant_id": user.tenant.id})
|
||||||
|
|
||||||
# 设置cookie
|
# 设置cookie
|
||||||
response.set_cookie(key="session_token", value=token, httponly=True)
|
response.set_cookie(
|
||||||
|
key="session_token",
|
||||||
|
value=token,
|
||||||
|
httponly=True,
|
||||||
|
# domain=".ecs2.heshunme.xyz", # 确保域正确
|
||||||
|
samesite="none", # 根据需要设置samesite属性
|
||||||
|
secure=True,
|
||||||
|
)
|
||||||
|
|
||||||
# 关闭数据库会话
|
# 关闭数据库会话
|
||||||
session.close()
|
session.close()
|
||||||
|
|||||||
3
main.py
3
main.py
@ -24,7 +24,8 @@ app = FastAPI(lifespan=lifespan)
|
|||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"], # 允许所有来源,也可以指定具体的来源,例如 ["http://example.com", "https://example.com"]
|
# allow_origins=["*"],
|
||||||
|
allow_origins=["http://localhost:8080","http://localhost:5000"], # 允许所有来源,也可以指定具体的来源,例如 ["http://example.com", "https://example.com"]
|
||||||
allow_credentials=True, # 允许携带凭证(如cookies)
|
allow_credentials=True, # 允许携带凭证(如cookies)
|
||||||
allow_methods=["*"], # 允许所有方法,也可以指定具体的方法,例如 ["GET", "POST", "PUT", "DELETE"]
|
allow_methods=["*"], # 允许所有方法,也可以指定具体的方法,例如 ["GET", "POST", "PUT", "DELETE"]
|
||||||
allow_headers=["*"], # 允许所有头部,也可以指定具体的头部,例如 ["Content-Type", "Authorization"]
|
allow_headers=["*"], # 允许所有头部,也可以指定具体的头部,例如 ["Content-Type", "Authorization"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user