diff --git a/src/main/frontend/src/App.tsx b/src/main/frontend/src/App.tsx index 4d53b30..b15302b 100644 --- a/src/main/frontend/src/App.tsx +++ b/src/main/frontend/src/App.tsx @@ -1,4 +1,4 @@ -import {useCallback, useState} from 'react'; +import {useCallback, useEffect, useState} from 'react'; import {Button} from "@/components/ui/button"; import { Table, @@ -17,14 +17,14 @@ function App() { const navigate = useNavigate(); const getFakeAccounts = useCallback(() => { - fetch("http://localhost:8080/accounts") + fetch("/api/accounts") .then(response => response.json()) .then(data => setAccounts(data)) .catch(error => console.error(error)); }, [accounts]); const postFakeAccount = () => { - fetch("http://localhost:8080/account", { + fetch("/api/account", { method: "POST", headers: { "Content-Type": "application/json" @@ -42,6 +42,10 @@ function App() { .catch(error => console.error(error)); }; + useEffect(() => { + getFakeAccounts(); + }, []); + return (

Commerce Bank Frontend

diff --git a/src/main/frontend/src/routes/Login.tsx b/src/main/frontend/src/routes/Login.tsx index 5e4f72f..4abb75e 100644 --- a/src/main/frontend/src/routes/Login.tsx +++ b/src/main/frontend/src/routes/Login.tsx @@ -36,7 +36,7 @@ function Login() { }) const onSubmit = (data: z.infer) => { - fetch("http://localhost:8080/login", { + fetch("/api/login", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/src/main/frontend/vite.config.ts b/src/main/frontend/vite.config.ts index 908d5ca..c79223d 100644 --- a/src/main/frontend/vite.config.ts +++ b/src/main/frontend/vite.config.ts @@ -6,6 +6,12 @@ export default defineConfig({ plugins: [react()], server: { port: 3000, + proxy: { + "/api": { + target: "http://localhost:8080", + rewrite: (path) => path.replace(/^\/api/, ""), //removes /api prefix from the request path + }, + }, }, resolve: { alias: {