fix: remove backend placeholders
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"name": "zui-backend",
|
||||
"version": "1.0.0",
|
||||
"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",
|
||||
"scripts": {
|
||||
"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).
|
||||
*/
|
||||
|
||||
@@ -14,72 +14,6 @@ const app = express()
|
||||
app.use(cors({ origin: CORS_ORIGIN }))
|
||||
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 }. */
|
||||
function buildAgentRequest(body) {
|
||||
const { prompt, context, contextNodes, connection: conn, reasoning } = body ?? {}
|
||||
|
||||
Reference in New Issue
Block a user