Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

data.js

27 lines571 Bytes

1const items = []
2​
3export default async (req, res) => {
4 await new Promise((r) => setTimeout(r, 1000))
5​
6 if (req.method === 'POST') {
7 const { text } = req.body
8​
9 // sometimes it will fail, this will cause a regression on the UI
10​
11 if (Math.random() > 0.7) {
12 res.status(500)
13 res.json({ message: 'Could not add item!' })
14 return
15 }
16​
17 const newTodo = { id: Math.random().toString(), text: text.toUpperCase() }
18 items.push(newTodo)
19 res.json(newTodo)
20 return
21 } else {
22 res.json({
23 ts: Date.now(),
24 items,
25 })
26 }