quivr CORS issue on local development

goucqfw6  于 2个月前  发布在  其他
关注(0)|答案(2)|浏览(39)

发生了什么?
当尝试在Mac上使用docker compose -f docker-compose.dev.yml up --build本地构建应用程序时,前端无法与后端进行通信,原因是CORS错误。我认为这与Docker有关?
相关日志输出

  • 无响应*

Twitter / LinkedIn详细信息

  • 无响应*
pobjuy32

pobjuy321#

嘿,@Amirjab21!👋 我来帮助你解决任何bug、问题或者成为贡献者。让我们一起解决这些烦人的bug吧!
要解决在Mac上使用Docker构建应用程序时遇到的CORS问题,你需要确保后端服务正确配置以处理CORS请求。这通常涉及到在你的FastAPI应用程序中设置CORS中间件。
以下是如何将CORS中间件添加到你的FastAPI应用的方法:

  1. 打开你的FastAPI应用程序文件(例如,main.py)。
  2. fastapi.middleware.cors导入必要的CORS中间件。
  3. 将CORS中间件添加到你的FastAPI应用。
    以下是向你的FastAPI应用添加CORS中间件的示例代码片段:
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

# Define the allowed origins
origins = [
    "http://localhost",
    "http://localhost:3000",
    "http://localhost:3001",
    "https://quivr.app",
    "https://www.quivr.app",
    "http://quivr.app",
    "http://www.quivr.app",
    "https://chat.quivr.app",
    "*",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Your existing routes and logic
@app.get("/")
def read_root():
    return {"Hello": "World"}

# Other routes and logic

在进行这些更改后,使用以下命令重建并启动Docker容器:

docker compose -f docker-compose.dev.yml up --build

这应该解决了本地开发上的CORS问题。

  • 要继续与1(https://github.com/QuivrHQ/quivr/blob/main/docker-compose.dev.yml)2(https://github.com/QuivrHQ/quivr/blob/main/backend/middlewares/cors.py)交流,请提及@dosu。*
jhiyze9q

jhiyze9q2#

这是由于在使用Ollama时未运行supabase迁移所导致的。

相关问题