fix: remove backend placeholders
This commit is contained in:
11
README.md
11
README.md
@@ -36,7 +36,7 @@ cd frontend && npm install && npm run dev
|
|||||||
# → http://localhost:3000
|
# → http://localhost:3000
|
||||||
```
|
```
|
||||||
|
|
||||||
**Frontend + backend** (so the app can show “Backend API: N todos”):
|
**Frontend + backend** (for AI agent and health):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Terminal 1 – backend
|
# Terminal 1 – backend
|
||||||
@@ -45,7 +45,7 @@ cd backend && npm install && npm run dev
|
|||||||
|
|
||||||
# Terminal 2 – frontend
|
# Terminal 2 – frontend
|
||||||
cd frontend && npm install && npm run dev
|
cd frontend && npm install && npm run dev
|
||||||
# → http://localhost:3000 (Vite proxies /api/todos to backend)
|
# → http://localhost:3000 (Vite proxies /api/* and /health to backend)
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -89,16 +89,9 @@ For self-hosting (e.g. Tailscale/HTTPS): set `CORS_ORIGIN` to your frontend URL;
|
|||||||
|
|
||||||
| Method | Path | Description |
|
| Method | Path | Description |
|
||||||
|--------|------|-------------|
|
|--------|------|-------------|
|
||||||
| GET | `/api/todos` | List all todos. |
|
|
||||||
| GET | `/api/todos/:id` | Get one todo. |
|
|
||||||
| POST | `/api/todos` | Create (`{ "title": "...", "completed": false }`). |
|
|
||||||
| PUT | `/api/todos/:id` | Update. |
|
|
||||||
| DELETE | `/api/todos/:id` | Delete. |
|
|
||||||
| GET | `/health` | Health check (e.g. for Docker). |
|
| GET | `/health` | Health check (e.g. for Docker). |
|
||||||
| POST | `/api/agent` | Run AI agent; body `{ "prompt", "context?", "contextNodes?" }` → `{ "markdown" }`. |
|
| POST | `/api/agent` | Run AI agent; body `{ "prompt", "context?", "contextNodes?" }` → `{ "markdown" }`. |
|
||||||
|
|
||||||
Data is in-memory (resets on restart). Add a JSON file or DB later if needed.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Agent node (local LLM or OpenAI)
|
## Agent node (local LLM or OpenAI)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "zui-backend",
|
"name": "zui-backend",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Minimal Express API for Zui (todos CRUD, no DB)",
|
"description": "Minimal Express API for Zui (agent, health; no DB)",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/index.js",
|
"start": "node src/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Minimal Express API: /api/todos CRUD (in-memory).
|
* Minimal Express API: /api/agent, /health.
|
||||||
* No DB, no auth. CORS allowed for frontend. Production-ready env (PORT, CORS_ORIGIN).
|
* No DB, no auth. CORS allowed for frontend. Production-ready env (PORT, CORS_ORIGIN).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -14,72 +14,6 @@ const app = express()
|
|||||||
app.use(cors({ origin: CORS_ORIGIN }))
|
app.use(cors({ origin: CORS_ORIGIN }))
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
|
|
||||||
// In-memory store (replace with JSON file or DB later)
|
|
||||||
let todos = [
|
|
||||||
{ id: '1', title: 'Sample todo', completed: false },
|
|
||||||
{ id: '2', title: 'Another item', completed: true },
|
|
||||||
]
|
|
||||||
let nextId = 3
|
|
||||||
|
|
||||||
/** GET /api/todos — list all */
|
|
||||||
app.get('/api/todos', (req, res) => {
|
|
||||||
try {
|
|
||||||
res.json(todos)
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/** GET /api/todos/:id — get one */
|
|
||||||
app.get('/api/todos/:id', (req, res) => {
|
|
||||||
try {
|
|
||||||
const todo = todos.find((t) => t.id === req.params.id)
|
|
||||||
if (!todo) return res.status(404).json({ error: 'Not found' })
|
|
||||||
res.json(todo)
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/** POST /api/todos — create */
|
|
||||||
app.post('/api/todos', (req, res) => {
|
|
||||||
try {
|
|
||||||
const { title, completed } = req.body ?? {}
|
|
||||||
const id = String(nextId++)
|
|
||||||
const todo = { id, title: title ?? '', completed: Boolean(completed) }
|
|
||||||
todos.push(todo)
|
|
||||||
res.status(201).json(todo)
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/** PUT /api/todos/:id — update */
|
|
||||||
app.put('/api/todos/:id', (req, res) => {
|
|
||||||
try {
|
|
||||||
const idx = todos.findIndex((t) => t.id === req.params.id)
|
|
||||||
if (idx === -1) return res.status(404).json({ error: 'Not found' })
|
|
||||||
const { title, completed } = req.body ?? {}
|
|
||||||
if (title !== undefined) todos[idx].title = title
|
|
||||||
if (completed !== undefined) todos[idx].completed = Boolean(completed)
|
|
||||||
res.json(todos[idx])
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/** DELETE /api/todos/:id — delete */
|
|
||||||
app.delete('/api/todos/:id', (req, res) => {
|
|
||||||
try {
|
|
||||||
const idx = todos.findIndex((t) => t.id === req.params.id)
|
|
||||||
if (idx === -1) return res.status(404).json({ error: 'Not found' })
|
|
||||||
const removed = todos.splice(idx, 1)[0]
|
|
||||||
res.json(removed)
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/** Build OpenAI client and full prompt from request body. Returns { openai, modelId, fullPrompt } or { error }. */
|
/** Build OpenAI client and full prompt from request body. Returns { openai, modelId, fullPrompt } or { error }. */
|
||||||
function buildAgentRequest(body) {
|
function buildAgentRequest(body) {
|
||||||
const { prompt, context, contextNodes, connection: conn, reasoning } = body ?? {}
|
const { prompt, context, contextNodes, connection: conn, reasoning } = body ?? {}
|
||||||
|
|||||||
@@ -194,16 +194,6 @@ export function CanvasPage({ projectId }: CanvasPageProps) {
|
|||||||
graphRef.current.nodes = nodes
|
graphRef.current.nodes = nodes
|
||||||
graphRef.current.edges = edges
|
graphRef.current.edges = edges
|
||||||
|
|
||||||
const [apiTodosCount, setApiTodosCount] = React.useState<number | null>(null)
|
|
||||||
React.useEffect(() => {
|
|
||||||
fetch('/api/todos')
|
|
||||||
.then((r) => r.json())
|
|
||||||
.then((data: unknown) => {
|
|
||||||
if (Array.isArray(data)) setApiTodosCount(data.length)
|
|
||||||
})
|
|
||||||
.catch(() => setApiTodosCount(-1))
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const pendingChangesRef = useRef<NodeChange<Node>[]>([])
|
const pendingChangesRef = useRef<NodeChange<Node>[]>([])
|
||||||
const rafRef = useRef<number | null>(null)
|
const rafRef = useRef<number | null>(null)
|
||||||
const onNodesChange = useCallback(
|
const onNodesChange = useCallback(
|
||||||
@@ -644,11 +634,6 @@ export function CanvasPage({ projectId }: CanvasPageProps) {
|
|||||||
canCopy={selectedNodes.length === 1}
|
canCopy={selectedNodes.length === 1}
|
||||||
onFitView={() => flowActionsRef.current?.fitView?.()}
|
onFitView={() => flowActionsRef.current?.fitView?.()}
|
||||||
/>
|
/>
|
||||||
{apiTodosCount !== null && (
|
|
||||||
<div className="shrink-0 px-3 py-1 text-xs text-muted-foreground border-b border-border/50">
|
|
||||||
Backend API: {apiTodosCount >= 0 ? `${apiTodosCount} todos` : 'unavailable'}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="flex-1 min-h-0 relative flex flex-col">
|
<div className="flex-1 min-h-0 relative flex flex-col">
|
||||||
<div className="flex-1 min-h-0 flex flex-col">
|
<div className="flex-1 min-h-0 flex flex-col">
|
||||||
<GraphContext.Provider value={graphContextValue}>
|
<GraphContext.Provider value={graphContextValue}>
|
||||||
|
|||||||
@@ -8,14 +8,6 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
// Backend API (dev): proxy to avoid CORS
|
// Backend API (dev): proxy to avoid CORS
|
||||||
'/api/todos': {
|
|
||||||
target: 'http://localhost:8080',
|
|
||||||
changeOrigin: true,
|
|
||||||
},
|
|
||||||
'/api/todos/': {
|
|
||||||
target: 'http://localhost:8080',
|
|
||||||
changeOrigin: true,
|
|
||||||
},
|
|
||||||
'/health': {
|
'/health': {
|
||||||
target: 'http://localhost:8080',
|
target: 'http://localhost:8080',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user