Open History to see the last commit
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 }
27}