feat: wire BuildPulse to Appwrite-backed persistence
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import express from 'express'
|
||||
import { checkBackendHealth, fetchStoredAppState, persistAppState } from './appwriteBackend.mjs'
|
||||
|
||||
const app = express()
|
||||
const port = Number(process.env.BUILDPULSE_API_PORT || 8788)
|
||||
|
||||
app.use(express.json({ limit: '2mb' }))
|
||||
|
||||
app.get('/api/health', async (_req, res) => {
|
||||
try {
|
||||
const health = await checkBackendHealth()
|
||||
res.json(health)
|
||||
} catch (error) {
|
||||
res.status(500).json({ ok: false, backend: 'appwrite', error: error?.message || 'Unknown backend error' })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/state', async (_req, res) => {
|
||||
try {
|
||||
const state = await fetchStoredAppState()
|
||||
res.json({ ok: true, backend: 'appwrite', state })
|
||||
} catch (error) {
|
||||
res.status(500).json({ ok: false, backend: 'appwrite', error: error?.message || 'Failed to fetch state' })
|
||||
}
|
||||
})
|
||||
|
||||
app.put('/api/state', async (req, res) => {
|
||||
const state = req.body?.state
|
||||
if (!state || typeof state !== 'object') {
|
||||
res.status(400).json({ ok: false, error: 'Request body must include a state object.' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await persistAppState(state)
|
||||
res.json({ ok: true, backend: 'appwrite' })
|
||||
} catch (error) {
|
||||
res.status(500).json({ ok: false, backend: 'appwrite', error: error?.message || 'Failed to persist state' })
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`BuildPulse API listening on http://127.0.0.1:${port}`)
|
||||
})
|
||||
Reference in New Issue
Block a user