LocalAI icon indicating copy to clipboard operation
LocalAI copied to clipboard

Cors Problem Using JS Axios

Open Andreh1982 opened this issue 1 year ago • 3 comments

Excuse me, hello!

I'm facing a issue using a JS front-end to connect to the LocalAI API. I saw the issue about the Cors fix, but it still doesn't work.

I also tried to disable cors in axios, but with that option i cant retrieve the body response.

Axios Function(i'm a newbie, please be nice <3)

function StartShowPayload() { const [payload, setPayload] = useState([]); useEffect(async () => { axios.get("http://192.168.2.32:8080/models", ).then((res) => { const threads = res; setPayload(threads); }); }, []);

LocalAI API is running in another computer inside my local network, Thank you so much for your time! :)

Andreh1982 avatar Jun 13 '23 21:06 Andreh1982

You can set corsAllowedOrigins in the .env

mike-niemand avatar Jun 14 '23 13:06 mike-niemand

Hey Mike, thank you! Should i set, like:

corsAllowedOrigins = "*"

Or

CORSALLOWEDORIGINS = "*"

?

Andreh1982 avatar Jun 14 '23 13:06 Andreh1982

I've used the first but I've set it explicitly. Setting wildcards can creep into production. Look at api.go and you can see how this is implemented.

On Wed, 14 Jun 2023, 15:18 Andreh1982, @.***> wrote:

Hey Mike, thank you! Should i set, like:

corsAllowedOrigins = "*"

Or

CORSALLOWEDORIGINS = "*"

?

— Reply to this email directly, view it on GitHub https://github.com/go-skynet/LocalAI/issues/585#issuecomment-1591194739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGK4ZK6GXXQ5AHCS3TWCAC3XLG23BANCNFSM6AAAAAAZFOPH74 . You are receiving this because you commented.Message ID: @.***>

mike-niemand avatar Jun 14 '23 13:06 mike-niemand

Did you ever get this sorted?

greyhammer avatar Jun 19 '23 22:06 greyhammer

Hello! :)

No, unfortunately nope... I tried as our friend there told me but no success. The project i'm doing haves another API who calls the LocalAI API, so i just moved the front to call new API. :)

I will close this issue, thank you so much for helping me!

Andreh1982 avatar Jun 20 '23 12:06 Andreh1982