WebSocket在vite项目的proxy中配置代理

代码如下:

proxy: {
	"/websocket-api": {
		target: "ws://192.168.1.6:3000",
		changeOrigin: true,
		ws: true,
		rewrite: (path: string) => path.replace(/^\/websocket-api/, "")
	}
}

使用时:

const currentUrl = window.location.host;
const currentWs = window.location.protocol === "https:" ? "wss" : "ws";
const ws = new WebSocketTool(
	`${currentWs}://${currentUrl}/websocket-api?Authorization=`+ token
);

你可能感兴趣的:(websocket,python,网络协议)