set up flask proxy

This commit is contained in:
Silas Bartha 2025-02-09 01:37:14 -05:00
parent 316c025ae8
commit 40e178874e
4 changed files with 24 additions and 33 deletions

View File

@ -3,6 +3,6 @@ from flask import Flask
app = Flask(__name__) app = Flask(__name__)
@app.route('/time') @app.route('/api/time')
def get_current_time(): def get_current_time():
return {'time': time.time()} return {'time': time.time()}

View File

@ -25,6 +25,5 @@
"eslint-plugin-react-refresh": "^0.4.18", "eslint-plugin-react-refresh": "^0.4.18",
"globals": "^15.14.0", "globals": "^15.14.0",
"vite": "^6.1.0" "vite": "^6.1.0"
}, }
"proxy": "http://localhost:5000"
} }

View File

@ -1,35 +1,22 @@
import { useState } from 'react' import { useEffect, useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css' import './App.css'
function App() { function App() {
const [count, setCount] = useState(0) const [currentTime, setCurrentTime] = useState(0);
useEffect(() => {
fetch('/api/time').then(res => res.json()).then(data => {
setCurrentTime(data.time);
});
}, []);
return ( return (
<> <div className="App">
<div> <header className="App-header">
<a href="https://vite.dev" target="_blank"> <p>The current time is {currentTime}.</p>
<img src={viteLogo} className="logo" alt="Vite logo" /> </header>
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div> </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>
</>
) )
} }
export default App export default App;

View File

@ -4,4 +4,9 @@ import react from '@vitejs/plugin-react'
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
server: {
proxy: {
'/api': 'http://localhost:5000',
},
},
}) })