promptfoo / promptfoo

Test your prompts, agents, and RAGs. Use LLM evals to improve your app's quality and catch problems. Compare performance of GPT, Claude, Gemini, Llama, and more. Simple declarative configs with command line and CI/CD integration.

Home Page:https://www.promptfoo.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CORS error when using self hosted server

NathanKarthik1996 opened this issue · comments

I keep running into a cors error if I access my self hosted server that is on a ec2 instance. If I disable cors on my browser however, I am able to reach out to it. I do see the app.use (cors()) in the server.ts, but I'm not sure if this error is coming from that. Does the middleware or nextjs config need to handle cors?

For additional context, this error happens when I use the share button.

Here is the curl response from the header:

HTTP/1.1 200 OK
cache-control: s-maxage=31536000, stale-while-revalidate
content-length: 7257
content-type: text/html; charset=utf-8
date: Tue, 30 Apr 2024 21:37:12 GMT
etag: "162s16q4lu25ll"
Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding
x-nextjs-cache: HIT
x-powered-by: Next.js
Connection: keep-alive
Keep-Alive: timeout=5

Not sure about this one. As far as I'm aware there isn't any special cors stuff you'd have to do on your side. The self-hosted version is meant to be bundled as a single app using the Dockerfile, whereas server.ts is the devtool that runs locally. So you might want to try running the Dockerfile/next.js app instead of running server.ts/promptfoo view.

I'm using the nextui that is built from the DockerFile, I was able to fix this by making the middleware.ts handle the cors and preflight responses. Not sure if this is a use case that you would need here though tbh, if it is happy to contribute here.

I'm using the nextui that is built from the DockerFile, I was able to fix this by making the middleware.ts handle the cors and preflight responses. Not sure if this is a use case that you would need here though tbh, if it is happy to contribute here.