aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <silas@exvacuum.dev>2025-02-09 01:37:14 -0500
committerLibravatar Silas Bartha <silas@exvacuum.dev>2025-02-09 01:37:14 -0500
commit40e178874e129545c7de06f9f63a8ba15b93d1a2 (patch)
treed5c3d3a2f7c04e2f05e5bf994a95dd62bde92db6
parent316c025ae86b4fdee2777e95ce950b11a5c1f73b (diff)
set up flask proxy
-rw-r--r--api/api.py2
-rw-r--r--package.json3
-rw-r--r--src/App.jsx45
-rw-r--r--vite.config.js7
4 files changed, 24 insertions, 33 deletions
diff --git a/api/api.py b/api/api.py
index 3e16e58..64d9fe5 100644
--- a/api/api.py
+++ b/api/api.py
@@ -3,6 +3,6 @@ from flask import Flask
app = Flask(__name__)
-@app.route('/time')
+@app.route('/api/time')
def get_current_time():
return {'time': time.time()}
diff --git a/package.json b/package.json
index ae544fc..2620335 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,5 @@
"eslint-plugin-react-refresh": "^0.4.18",
"globals": "^15.14.0",
"vite": "^6.1.0"
- },
- "proxy": "http://localhost:5000"
+ }
}
diff --git a/src/App.jsx b/src/App.jsx
index f67355a..2f196f9 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,35 +1,22 @@
-import { useState } from 'react'
-import reactLogo from './assets/react.svg'
-import viteLogo from '/vite.svg'
+import { useEffect, useState } from 'react'
import './App.css'
function App() {
- const [count, setCount] = useState(0)
+ const [currentTime, setCurrentTime] = useState(0);
- return (
- <>
- <div>
- <a href="https://vite.dev" target="_blank">
- <img src={viteLogo} className="logo" alt="Vite logo" />
- </a>
- <a href="https://react.dev" target="_blank">
- <img src={reactLogo} className="logo react" alt="React logo" />
- </a>
- </div>
- <h1>Vite + React</h1>
- <div className="card">
- <button onClick={() => setCount((count) => count + 1)}>
- count is {count}
- </button>
- <p>
- Edit <code>src/App.jsx</code> and save to test HMR
- </p>
- </div>
- <p className="read-the-docs">
- Click on the Vite and React logos to learn more
- </p>
- </>
- )
+ useEffect(() => {
+ fetch('/api/time').then(res => res.json()).then(data => {
+ setCurrentTime(data.time);
+ });
+ }, []);
+
+ return (
+ <div className="App">
+ <header className="App-header">
+ <p>The current time is {currentTime}.</p>
+ </header>
+ </div>
+ )
}
-export default App
+export default App;
diff --git a/vite.config.js b/vite.config.js
index 8b0f57b..df070a7 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -3,5 +3,10 @@ import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
- plugins: [react()],
+ plugins: [react()],
+ server: {
+ proxy: {
+ '/api': 'http://localhost:5000',
+ },
+ },
})