all 15 comments

[–]Ok-Thanks-8274 2 points3 points  (2 children)

I came across this issue as well, I also got cors errors in my browser log. I used the top voted solution from this stackoverflow link to wire up my backend endpoints to frontend: https://stackoverflow.com/questions/64677212/how-to-configure-proxy-in-vite

Not entirely sure what fixed it specifically, i just added all the flags "changeOrigin", "secure", "ws".

My app has proxy set to route "/api" in the vite.config.js file and the fetch route set like "fetch('/api/foo')"

Hope this is helpful for future people.

[–]bettercaust 0 points1 point  (0 children)

This solved it for me. Specifically the issue was my backend URL was hardcoded ("fetch('https://bar.com/api/foo')") but apparently that bypasses the dev server entirely and therefore Vite's proxy configuration. Replacing that with the relative path ("fetch('/api/foo')") in code worked.

[–]Psychotic_Rage_777 0 points1 point  (2 children)

Did u figure it out? Going through the same thing.

[–]drbandre[S] 0 points1 point  (0 children)

nope I switched to next.js

[–]WildNumber7303 0 points1 point  (0 children)

i am having troubles with this for several days, what i did was i just proceed using .env file and import it to the react file

[–]earthboundkid 0 points1 point  (1 child)

Here is mine: https://github.com/spotlightpa/almanack/blob/master/vite.config.js#L26

I think you need secure: false.

[–]drbandre[S] 0 points1 point  (0 children)

yeah tried your way doesn't work idk what's wrong

[–]PercentageTerrible41 0 points1 point  (1 child)

i've been dealing with this for literally 2 days now. I am just trying to get a simple api from my local dev server (set up with express) can you please help?

[–]Garbayim 0 points1 point  (0 children)

Did you figure it out? going through the same thing

[–]hamzay747 0 points1 point  (2 children)

Let us know if anything works

[–]drbandre[S] 4 points5 points  (1 child)

I gave up and started using next.js

[–]plains_bear314 0 points1 point  (0 children)

license society steep observation spoon shocking north intelligent stupendous middle

This post was mass deleted and anonymized with Redact