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 items.push(text.toUpperCase())
18 res.json(text.toUpperCase())
19 return
20 } else {
21 res.json({
22 ts: Date.now(),
23 items,
24 })
25 }
26}