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);
return ( useEffect(() => {
<> fetch('/api/time').then(res => res.json()).then(data => {
<div> setCurrentTime(data.time);
<a href="https://vite.dev" target="_blank"> });
<img src={viteLogo} className="logo" alt="Vite logo" /> }, []);
</a>
<a href="https://react.dev" target="_blank"> return (
<img src={reactLogo} className="logo react" alt="React logo" /> <div className="App">
</a> <header className="App-header">
</div> <p>The current time is {currentTime}.</p>
<h1>Vite + React</h1> </header>
<div className="card"> </div>
<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

@ -3,5 +3,10 @@ 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',
},
},
}) })