代码如下:
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 ws = new WebSocketTool(
`ws://${currentUrl}/websocket-api?Authorization=`+ token
);