fixed cookies and CORS
Browse files- Dockerfile +3 -2
- Makefile +6 -0
- README.md +2 -2
- backend/src/app.py +5 -4
- frontend/src/App.tsx +1 -1
- frontend/src/components/BackendHealthCheck.tsx +0 -5
Dockerfile
CHANGED
@@ -28,6 +28,7 @@ RUN if [ -n "$SPACE_HOST" ]; then \
|
|
28 |
VITE_BACKEND_URL="$SPACE_HOST" pnpm build; \
|
29 |
else \
|
30 |
echo "Building without SPACE_HOST"; \
|
|
|
31 |
pnpm build; \
|
32 |
fi
|
33 |
|
@@ -80,7 +81,7 @@ ENV FRONTEND_PATH=/app/frontend/dist
|
|
80 |
USER appuser
|
81 |
|
82 |
# Expose port (adjust if needed)
|
83 |
-
EXPOSE
|
84 |
|
85 |
# Run FastAPI via uvicorn
|
86 |
-
CMD ["uvicorn", "backend.src.app:app", "--host", "0.0.0.0", "--port", "
|
|
|
28 |
VITE_BACKEND_URL="$SPACE_HOST" pnpm build; \
|
29 |
else \
|
30 |
echo "Building without SPACE_HOST"; \
|
31 |
+
VITE_BACKEND_URL="http://127.0.0.1:9481" \
|
32 |
pnpm build; \
|
33 |
fi
|
34 |
|
|
|
81 |
USER appuser
|
82 |
|
83 |
# Expose port (adjust if needed)
|
84 |
+
EXPOSE 9481
|
85 |
|
86 |
# Run FastAPI via uvicorn
|
87 |
+
CMD ["uvicorn", "backend.src.app:app", "--host", "0.0.0.0", "--port", "9481"]
|
Makefile
CHANGED
@@ -10,3 +10,9 @@ style:
|
|
10 |
quality:
|
11 |
cd $(BACKEND_DIR) && make quality
|
12 |
cd $(FRONTEND_DIR) && pnpm quality
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
quality:
|
11 |
cd $(BACKEND_DIR) && make quality
|
12 |
cd $(FRONTEND_DIR) && pnpm quality
|
13 |
+
|
14 |
+
docker-build:
|
15 |
+
docker build -t docker-space-fastapi-react .
|
16 |
+
|
17 |
+
docker-run:
|
18 |
+
docker run -e HF_TOKEN -p 9481:9481 docker-space-fastapi-react
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 💻
|
|
4 |
colorFrom: blue
|
5 |
colorTo: green
|
6 |
sdk: docker
|
7 |
-
app_port:
|
8 |
pinned: false
|
9 |
license: mit
|
10 |
short_description: Template to vibe code a demo running on FastAPI + React
|
@@ -68,7 +68,7 @@ If you want to run it on your own, you can use Docker:
|
|
68 |
|
69 |
```bash
|
70 |
docker build -t fastapi-react-space .
|
71 |
-
docker run -p
|
72 |
```
|
73 |
|
74 |
Note that when running in Docker, the app runs in production mode without hot-reloading.
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: green
|
6 |
sdk: docker
|
7 |
+
app_port: 9481
|
8 |
pinned: false
|
9 |
license: mit
|
10 |
short_description: Template to vibe code a demo running on FastAPI + React
|
|
|
68 |
|
69 |
```bash
|
70 |
docker build -t fastapi-react-space .
|
71 |
+
docker run -e HF_TOKEN -p 9481:9481 fastapi-react-space
|
72 |
```
|
73 |
|
74 |
Note that when running in Docker, the app runs in production mode without hot-reloading.
|
backend/src/app.py
CHANGED
@@ -23,14 +23,15 @@ async def lifespan(app: FastAPI):
|
|
23 |
app = FastAPI(lifespan=lifespan)
|
24 |
|
25 |
|
26 |
-
#
|
27 |
app.add_middleware(
|
28 |
CORSMiddleware,
|
29 |
allow_origins=[
|
30 |
-
"
|
31 |
"http://localhost:5173",
|
32 |
-
"
|
33 |
-
"
|
|
|
34 |
],
|
35 |
allow_credentials=True,
|
36 |
allow_methods=["*"],
|
|
|
23 |
app = FastAPI(lifespan=lifespan)
|
24 |
|
25 |
|
26 |
+
# Set CORS headers
|
27 |
app.add_middleware(
|
28 |
CORSMiddleware,
|
29 |
allow_origins=[
|
30 |
+
# Can't use "*" because frontend doesn't like it with "credentials: true"
|
31 |
"http://localhost:5173",
|
32 |
+
"http://0.0.0.0:9481",
|
33 |
+
"http://localhost:9481",
|
34 |
+
"http://127.0.0.1:9481",
|
35 |
],
|
36 |
allow_credentials=True,
|
37 |
allow_methods=["*"],
|
frontend/src/App.tsx
CHANGED
@@ -6,7 +6,7 @@ import huggingfaceLogo from "./assets/huggingface.svg";
|
|
6 |
function App() {
|
7 |
return (
|
8 |
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 text-white flex flex-col">
|
9 |
-
<BackendHealthCheck />
|
10 |
|
11 |
<div className="text-center pt-8 pb-6">
|
12 |
<div className="flex items-center justify-center space-x-3 mb-4">
|
|
|
6 |
function App() {
|
7 |
return (
|
8 |
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 text-white flex flex-col">
|
9 |
+
{!import.meta.env.PROD && <BackendHealthCheck />}
|
10 |
|
11 |
<div className="text-center pt-8 pb-6">
|
12 |
<div className="flex items-center justify-center space-x-3 mb-4">
|
frontend/src/components/BackendHealthCheck.tsx
CHANGED
@@ -42,11 +42,6 @@ export function BackendHealthCheck({
|
|
42 |
return () => clearInterval(interval);
|
43 |
}, [healthCheckUrl, checkInterval]);
|
44 |
|
45 |
-
// Only render in development mode
|
46 |
-
if (import.meta.env.PROD) {
|
47 |
-
return null;
|
48 |
-
}
|
49 |
-
|
50 |
const handleCopyCode = async () => {
|
51 |
const codeText = `cd backend/\nmake install\nmake backend`;
|
52 |
try {
|
|
|
42 |
return () => clearInterval(interval);
|
43 |
}, [healthCheckUrl, checkInterval]);
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
const handleCopyCode = async () => {
|
46 |
const codeText = `cd backend/\nmake install\nmake backend`;
|
47 |
try {
|