I'm currently building a VueJS website that works with websockets, and I ran into an issue after adding a proxy for my websocket server (which uses Python|Flask)
Here's my proxy configuration (that works for the '/api') vite.config.ts
:
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
host: true,
proxy: {
'/api': {
target: 'http://127.0.0.1:5000/api',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
},
'/ws': {
target: 'ws://127.0.0.1:5000',
ws: true,
changeOrigin: true,
rewrite: path => path.replace(/^\/ws/, '')
}
}
}
})
Here's the code I use to attempt a connection :
// '/game' is the namespace I use.
const $socket = io('/ws/game', {
path: '/websocket'
});
$socket.connect();
Here's my server-side python code (to initialize the websocket server with Flask-SocketIO) :
socket = SocketIO(
app,
path = '/websocket',
cors_allowed_origins = '*'
)
There's no error showing up, I just don't get the usual "Connected" message.