feat: support cors

This commit is contained in:
gazedreamily 2023-06-09 01:13:55 +08:00
parent 756989c302
commit 8b4362fd6a

View File

@ -1,4 +1,5 @@
from fastapi import FastAPI # 导入FastAPI from fastapi import FastAPI # 导入FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn # uvicorn:主要用于加载和提供应用程序的服务器 import uvicorn # uvicorn:主要用于加载和提供应用程序的服务器
import requests import requests
import json import json
@ -16,6 +17,14 @@ headers = {
# 创建一个app实例 # 创建一个app实例
app = FastAPI() if env.get("docs") is not None and env.get("docs").lower() == "true" else FastAPI(openapi_url=None) app = FastAPI() if env.get("docs") is not None and env.get("docs").lower() == "true" else FastAPI(openapi_url=None)
# 配置 CORS 中间件
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 允许所有来源,可以根据需求进行配置
allow_credentials=True,
allow_methods=["*"], # 允许所有请求方法
allow_headers=["*"], # 允许所有请求头
)
# 获取酷我cookie # 获取酷我cookie
url = 'https://www.kuwo.cn/' url = 'https://www.kuwo.cn/'