Merge pull request #45 from joelmathewthomas/feature/websocket-proxy
Feature/websocket proxy
This commit is contained in:
@@ -35,29 +35,54 @@ function UploadPage() {
|
|||||||
const startLogs = async () => {
|
const startLogs = async () => {
|
||||||
setLogs([formatLogMessage("Initializing freqsplit")]);
|
setLogs([formatLogMessage("Initializing freqsplit")]);
|
||||||
|
|
||||||
setTimeout(() => {
|
setLogs((prevLogs) => [
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Connecting to server")]);
|
...prevLogs,
|
||||||
|
formatLogMessage("Connecting to server"),
|
||||||
|
]);
|
||||||
|
|
||||||
// Send GET request to /api/ping
|
axios
|
||||||
axios.get("/api/ping")
|
.get("/api/ping")
|
||||||
.then((ping_resp) => {
|
.then((ping_resp) => {
|
||||||
if (ping_resp.status === 200) {
|
if (ping_resp.status === 200) {
|
||||||
setTimeout(() => {
|
setLogs((prevLogs) => [
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Connection established successfully")]);
|
...prevLogs,
|
||||||
|
formatLogMessage("Connection established successfully"),
|
||||||
|
]);
|
||||||
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("Waiting for WebSocket connection"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const checkWebSocketConnection = () => {
|
||||||
|
if (isConnected) {
|
||||||
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("WebSocket connected"),
|
||||||
|
]);
|
||||||
setInputEnabled(true);
|
setInputEnabled(true);
|
||||||
}, 80);
|
} else {
|
||||||
} else {
|
setTimeout(checkWebSocketConnection, 100);
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Failed to connect to server")]);
|
}
|
||||||
}
|
};
|
||||||
})
|
|
||||||
.catch(() => {
|
checkWebSocketConnection();
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Failed to connect to server")]);
|
} else {
|
||||||
});
|
setLogs((prevLogs) => [
|
||||||
}, 90);
|
...prevLogs,
|
||||||
|
formatLogMessage("Failed to connect to server"),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("Failed to connect to server"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
startLogs();
|
startLogs();
|
||||||
}, []);
|
}, [isConnected]);
|
||||||
|
|
||||||
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { createContext, useContext, useEffect, useState } from "react";
|
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||||
|
|
||||||
const WEBSOCKET_URL = "ws://localhost:8000/ws/freqsplit/";
|
const WEBSOCKET_URL = "/ws/freqsplit/";
|
||||||
|
|
||||||
interface WebSocketContextType {
|
interface WebSocketContextType {
|
||||||
socket: WebSocket | null;
|
socket: WebSocket | null;
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ export default defineConfig({
|
|||||||
target: 'http://localhost:8000',
|
target: 'http://localhost:8000',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
'/ws': {
|
||||||
|
target: "ws://localhost:8000",
|
||||||
|
ws: true,
|
||||||
|
changeOrigin: true,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user