I have a problem accessing my warp api from react, even though I have my vite proxy set up like so:
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:3030/api/shop',
changeOrigin: false,
secure: false,
rewrite: path => path.replace('/api', ''),
}
},
},
plugins: [react()],
})
The warp api is set to allow any origins:
let cors = warp::cors()
.allow_any_origin()
.allow_methods(vec!["GET", "POST", "PATCH", "OPTIONS", "DELETE"]);
warp::path!("api" / "shop" / "available")
.and(warp::get())
.map(|| {
//Leftout logic...
let json = json!({"available": available});
Ok(warp::reply::json(&json))
})
.with(cors)
If I call my endpoints directly in browser ('http://localhost:3030/api/shop/available*) I get the desired output from my warp api but in case of calling the fetch from react I only get a 500 error cors problem and the warp endpoint is not even reached.
My rust server is a rewrite of an express server written in typescript, for the purpose of bettering my rust understanding. The previous express server didn't use any cors plugins and sends the exact same response.
Does anyone maybe know a solution? or anyone used react with vite & warp before?
Adjustment: Just turned on logging for my warp api and it seems like the endpoint is never even reached from the fetch call.