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.route('/time')
@app.route('/api/time')
def get_current_time():
return {'time': time.time()}

View File

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

View File

@ -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;

View File

@ -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',
},
},
})