#Problem with vite proxy not redireting my request to the target server

1 messages · Page 1 of 1 (latest)

faint shuttle
#

I have a client( on port 5173) and a server( on port 8080). I have been trying to make a request with fetch to the server through vite proxy. But it keep making request to the client server with port 5173. My proxy config is like this
server: {
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: false,
ws:true,
rewrite: (path) => path.replace(/^/api/, '')
}
}
}

and I make a request like this:
const request=await fetch('/api/login/')

lyric lintel
#

Hi, you might have missed port: <CLIENT_PORT>, just before proxy

Edit: here's my working proxy
server: { port: 3000, proxy: { '/api': { target: 'http://localhost:5000', changeOrigin: true, }, }, },

faint shuttle
#

so i have to add something like port:5173, right?

lyric lintel
#

yes, if my guess is right

faint shuttle
#

ok i'll try it, thanks

#

it still making request to port 3000 :{

#

please someone help

lyric lintel
faint shuttle
#

yes i have changed it my config look like this:

#

server: {
port:3000,
host:true,
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: false,
// agent: new http.Agent(),
ws:true,
rewrite: (path) => path.replace(/^/api/, '')
}
}
}

#

when i run dev it serve at port 3000

#

and my request is still not working

lyric lintel
#

uhm might want to check this out

Edit:
//Proxying websockets or socket.io: ws://localhost:5173/socket.io -> ws://localhost:5174/socket.io '/socket.io': { target: 'ws://localhost:5174', ws: true, },

#

are you using websockets?

faint shuttle
#

Can I ask why I need to use web socket

lyric lintel
#

you don't have to if you don't need it. i just saw at your config ws:true so i'm assuming you do have websocket working with. also, i noticed you are using rewrite: YOUR PATH so i guess you are aware of where it leads to as well.

faint shuttle
#

Oh i have that because the other SO answer have that. The proxy is still not working 😩