diff --git a/web/src/App.jsx b/web/src/App.jsx
index 56e0b7d..95cc2ba 100644
--- a/web/src/App.jsx
+++ b/web/src/App.jsx
@@ -1,19 +1,17 @@
-import { useState } from 'react'
-import Header from './components/Header'
-import Footer from './components/Footer'
-import Endpoints from './components/Endpoints'
-import { QueryClient, QueryClientProvider, useQuery } from 'react-query'
-const queryClient = new QueryClient()
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import Endpoints from "./components/Endpoints";
+
function App() {
- return (
-
-
-
-
-
-
-
- )
+ return (
+ <>
+
+
+
+
+
+ >
+ );
}
-export default App
+export default App;
diff --git a/web/src/components/EndpointTable.jsx b/web/src/components/EndpointTable.jsx
index 7f14df1..348a02f 100644
--- a/web/src/components/EndpointTable.jsx
+++ b/web/src/components/EndpointTable.jsx
@@ -1,44 +1,44 @@
-import { Table, Thead, Tr, Th, Tbody, Td, Tooltip, Link } from '@chakra-ui/react'
-import React from 'react'
-import urlParse from 'https://cdn.skypack.dev/url-parse';
+import {
+ Table,
+ Thead,
+ Tr,
+ Th,
+ Tbody,
+ Td,
+ Tooltip,
+ Link,
+} from "@chakra-ui/react";
+import React from "react";
+import urlParse from "https://cdn.skypack.dev/url-parse";
const EndpointTable = ({ endpoints, onSelectedRow }) => {
-
- return (
- <>
-
-
-
-
- {
- Object.keys(endpoints[0]).map(k => ({k} | ))
- }
-
-
-
-
- {
- endpoints.map(endpoint => (
-
-
- onSelectedRow(endpoint)} key={endpoint.id}>
-
-
-
- {endpoint.id.split("-")[0]}
-
- |
-
- {urlParse(endpoint.path_url).pathname} |
- {endpoint.status ? '☠️ down' : '✅ up'} |
-
- ))
- }
-
-
-
- >
- )
-}
-
-export default EndpointTable
\ No newline at end of file
+ return (
+ <>
+
+
+
+ {Object.keys(endpoints[0]).map((k) => (
+ {k} |
+ ))}
+
+
+
+ {endpoints.map((endpoint) => (
+ onSelectedRow(endpoint)} key={endpoint.id}>
+
+
+ {endpoint.id.split("-")[0]}
+
+ |
+
+ {urlParse(endpoint.path_url).pathname} |
+ {endpoint.status ? "☠️ down" : "✅ up"} |
+
+ ))}
+
+
+ >
+ );
+};
+
+export default EndpointTable;
diff --git a/web/src/components/Endpoints.jsx b/web/src/components/Endpoints.jsx
index b1d232b..97a61f3 100644
--- a/web/src/components/Endpoints.jsx
+++ b/web/src/components/Endpoints.jsx
@@ -1,97 +1,64 @@
-import React, { Fragment, useEffect, useReducer, useState } from 'react'
-import EndpointCard from './EndpointCard'
-import { Box, Container, Flex, Heading, Text, Center } from "@chakra-ui/react"
-import { FaIdCard, FaTable } from 'react-icons/fa'
-import EndpointTable from './EndpointTable'
-import NoDataImage from './NoData'
-import { useQuery } from 'react-query'
+import React, { useState } from "react";
+import { Box, Container, Flex, Heading, Text, Center } from "@chakra-ui/react";
+import EndpointCard from "./EndpointCard";
+import { FaIdCard, FaTable } from "react-icons/fa";
+import EndpointTable from "./EndpointTable";
+import NoDataImage from "./NoData";
+import { useSocket } from "../hooks";
const Endpoints = () => {
-
- const [viewElement, setViewElement] = useState(false)
-
- const handleViewElement = () => {
- setViewElement(!viewElement)
- }
- const handleSelectedRow = (endpoint) => {
- console.log(endpoint)
- }
- const width = "100%";
-
- const { isLoading, error, data } = useQuery('endpointsData', () =>
- fetch('/api/v1/mngt/')
- .then(response =>
- response.json()
- )
- )
-
- if (isLoading) return 'Loading...'
-
- if (error) return 'An error has occurred: ' + error.message
-
-
- return (
- <>
-
-
- Ngonx Proxy!!
-
-
-
- Service Discovery
-
- {
-
- <>
-
- {viewElement
- ?
- :
- }
-
- {
- viewElement
- ? (
-
-
- {
- data.length > 0
- ?
- :
- }
-
-
-
- )
- : (
-
-
- {
- data.length > 0
- ? (
- {data.map((endpoint) => (
-
-
-
-
- ))}
-
)
- :
-
-
- }
-
- )
- }
- >
-
- }
-
- >
- )
-}
-export default Endpoints;
\ No newline at end of file
+ const [viewElement, setViewElement] = useState(false);
+ const { data, error } = useSocket("api/v1/mngt/wss");
+
+ const handleViewElement = () => {
+ setViewElement(!viewElement);
+ };
+ const handleSelectedRow = (endpoint) => {
+ console.log(endpoint);
+ };
+
+ if (error) return "An error has occurred: " + error;
+
+ return (
+ <>
+
+
+ Ngonx Proxy!!
+
+
+ Service Discovery
+
+
+ {viewElement ? : }
+
+ {viewElement ? (
+
+ {data.length > 0 ? (
+
+ ) : (
+
+ )}
+
+ ) : (
+
+ {data?.length > 0 ? (
+
+ {data.map((endpoint) => (
+
+ ))}
+
+ ) : (
+
+
+
+ )}
+
+ )}
+
+ >
+ );
+};
+export default Endpoints;
diff --git a/web/src/components/Footer.jsx b/web/src/components/Footer.jsx
index 0106bab..28ec0ac 100644
--- a/web/src/components/Footer.jsx
+++ b/web/src/components/Footer.jsx
@@ -1,64 +1,60 @@
import {
- Box,
- chakra,
- Stack,
- Text,
- VisuallyHidden,
- useColorModeValue,
- Center,
-} from '@chakra-ui/react';
-import { useStylesApp } from '../hooks/useStyleApp';
+ Box,
+ chakra,
+ Stack,
+ Text,
+ VisuallyHidden,
+ useColorModeValue,
+ Center,
+} from "@chakra-ui/react";
+import { useStylesApp } from "../hooks";
-
-export const SocialButton = ({
- children,
- label,
- href,
-}) => {
- return (
-
- {label}
- {children}
-
- );
+export const SocialButton = ({ children, label, href }) => {
+ return (
+
+ {label}
+ {children}
+
+ );
};
const ListHeader = ({ children }) => {
- return (
-
- {children}
-
- );
+ return (
+
+ {children}
+
+ );
};
export default function LargeWithNewsletter() {
- const { border, colorBase } = useStylesApp()
- return (
-
-
-
-
-
- © {new Date().getFullYear()} @kenriortega web page. All rights reserved
-
-
-
-
- );
-}
\ No newline at end of file
+ const { border, colorBase } = useStylesApp();
+ return (
+
+
+
+
+ © {new Date().getFullYear()} @kenriortega web page. All rights
+ reserved
+
+
+
+
+ );
+}
diff --git a/web/src/components/Header.jsx b/web/src/components/Header.jsx
index 05ac5f3..56bdf18 100644
--- a/web/src/components/Header.jsx
+++ b/web/src/components/Header.jsx
@@ -11,7 +11,7 @@ import {
} from "@chakra-ui/react";
import Logo from "./Logo";
import { FaSun, FaMoon, FaBars } from 'react-icons/fa'
-import { useStylesApp } from "../hooks/useStyleApp";
+import { useStylesApp } from "../hooks";
const NavBar = (props) => {
const [isOpen, setIsOpen] = React.useState(false);
const toggle = () => setIsOpen(!isOpen);
diff --git a/web/src/hooks/index.js b/web/src/hooks/index.js
new file mode 100644
index 0000000..486b8e6
--- /dev/null
+++ b/web/src/hooks/index.js
@@ -0,0 +1,2 @@
+export * from "./useSocket";
+export * from "./useStyleApp";
diff --git a/web/src/hooks/useSocket.js b/web/src/hooks/useSocket.js
new file mode 100644
index 0000000..f825439
--- /dev/null
+++ b/web/src/hooks/useSocket.js
@@ -0,0 +1,53 @@
+import { useState, useEffect, useMemo, useCallback } from "react";
+
+export const useSocket = (url) => {
+ const [data, setData] = useState(null);
+ const [error, setError] = useState(null);
+ const socket = useMemo(
+ () => new WebSocket(`ws://localhost:10001/${url}`),
+ []
+ );
+
+ socket.onmessage = useCallback(
+ (event) => {
+ console.log("Socket message: ", data);
+ return setData(event.data);
+ },
+ [socket]
+ );
+
+ socket.onerror = useCallback(
+ (error) => {
+ console.log("Socket error: ", error);
+ setError(error);
+ },
+ [socket]
+ );
+
+ socket.onclose = useCallback(
+ (event) => {
+ if (event.wasClean) {
+ setError(
+ `Connection closed cleanly, code=${event.code} reason=${event.reason}`
+ );
+ } else {
+ // server process killed or network down
+ setError("Connection died");
+ }
+ },
+ [socket]
+ );
+
+ const closeConnection = useCallback(
+ (code, reason) => {
+ socket.close(code, reason);
+ },
+ [socket]
+ );
+
+ useEffect(() => {
+ return closeConnection(1000, "Clean up");
+ }, []);
+
+ return { data, error, close: closeConnection };
+};