Commit 7fdbce6a authored by Kantz's avatar Kantz
Browse files

reverse proxy for development

parent 0e1d6e51
...@@ -61,6 +61,22 @@ python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 ...@@ -61,6 +61,22 @@ python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
npm run dev -- --host 0.0.0.0 npm run dev -- --host 0.0.0.0
``` ```
### Vite Proxy (Development)
The frontend now supports a dev proxy for API calls:
- Frontend requests `/api/...` to Vite
- Vite forwards `/api` to the backend target
Optional in `math-tutor/frontend/.env`:
```env
VITE_PROXY_TARGET="http://<BACKEND_HOST>:8000"
VITE_BACKEND_URL=""
```
`VITE_BACKEND_URL=""` keeps requests relative so they use the proxy. If you set `VITE_BACKEND_URL` to a full URL, requests bypass the proxy and CORS must be configured accordingly.
## Database (pgvector) setup ## Database (pgvector) setup
Ensure `POSTGRES_URL` and embedding env vars are in `backend/.env`: Ensure `POSTGRES_URL` and embedding env vars are in `backend/.env`:
......
...@@ -8,7 +8,8 @@ import type { ChatMessage } from "../components/Chat/MessageList"; ...@@ -8,7 +8,8 @@ import type { ChatMessage } from "../components/Chat/MessageList";
import type { RetrievedDoc } from "../components/Retrieval/DocPanel"; import type { RetrievedDoc } from "../components/Retrieval/DocPanel";
import { t } from "../i18n"; import { t } from "../i18n";
const backendUrl = import.meta.env.VITE_BACKEND_URL || "http://localhost:8000"; // Empty fallback uses Vite proxy (/api -> backend target) in development.
const backendUrl = import.meta.env.VITE_BACKEND_URL || "";
const initialMessages: ChatMessage[] = []; const initialMessages: ChatMessage[] = [];
......
...@@ -5,6 +5,14 @@ import react from '@vitejs/plugin-react' ...@@ -5,6 +5,14 @@ import react from '@vitejs/plugin-react'
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
server: { server: {
allowedHosts: ['vm11.fkc.hft-stuttgart.de'] host: "0.0.0.0",
port: 5173,
allowedHosts: ["vm11.fkc.hft-stuttgart.de"],
proxy: {
"/api": {
target: process.env.VITE_PROXY_TARGET || "http://localhost:8000",
changeOrigin: true,
},
},
}, },
}) })
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment