Spaces:
Running
Running
updates to serve frontend
Browse files- backend/__pycache__/app.cpython-313.pyc +0 -0
- backend/app.py +5 -0
- frontend/src/App.jsx +1 -1
- frontend/vite.config.js +5 -1
backend/__pycache__/app.cpython-313.pyc
CHANGED
|
Binary files a/backend/__pycache__/app.cpython-313.pyc and b/backend/__pycache__/app.cpython-313.pyc differ
|
|
|
backend/app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
@@ -14,6 +16,9 @@ app.add_middleware(
|
|
| 14 |
allow_headers=["Content-Type", "Authorization"], # only required headers
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
@app.get("/api/hello")
|
| 18 |
def greet_json():
|
| 19 |
return {"Hello": "World!"}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from pathlib import Path
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
|
|
| 16 |
allow_headers=["Content-Type", "Authorization"], # only required headers
|
| 17 |
)
|
| 18 |
|
| 19 |
+
frontend_path = Path(__file__).parent.parent / "frontend" / "dist"
|
| 20 |
+
app.mount("/", StaticFiles(directory=frontend_path, html=True), name="frontend")
|
| 21 |
+
|
| 22 |
@app.get("/api/hello")
|
| 23 |
def greet_json():
|
| 24 |
return {"Hello": "World!"}
|
frontend/src/App.jsx
CHANGED
|
@@ -9,7 +9,7 @@ function App() {
|
|
| 9 |
const [message, setMessage] = useState("");
|
| 10 |
|
| 11 |
useEffect(() => {
|
| 12 |
-
fetch("
|
| 13 |
.then(res => res.json())
|
| 14 |
.then(data => setMessage(data.Hello))
|
| 15 |
.catch(err => console.error(err));
|
|
|
|
| 9 |
const [message, setMessage] = useState("");
|
| 10 |
|
| 11 |
useEffect(() => {
|
| 12 |
+
fetch("/api/hello") // backend dev server
|
| 13 |
.then(res => res.json())
|
| 14 |
.then(data => setMessage(data.Hello))
|
| 15 |
.catch(err => console.error(err));
|
frontend/vite.config.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
import { defineConfig } from 'vite'
|
| 2 |
import react from '@vitejs/plugin-react'
|
| 3 |
|
| 4 |
-
// https://vite.dev/config/
|
| 5 |
export default defineConfig({
|
| 6 |
plugins: [react()],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
})
|
|
|
|
| 1 |
import { defineConfig } from 'vite'
|
| 2 |
import react from '@vitejs/plugin-react'
|
| 3 |
|
|
|
|
| 4 |
export default defineConfig({
|
| 5 |
plugins: [react()],
|
| 6 |
+
server: {
|
| 7 |
+
proxy: {
|
| 8 |
+
'/api': 'http://localhost:8000' // forward /api requests to FastAPI
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
})
|