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

data.ts

23 lines483 Bytes

1import type { NextApiRequest, NextApiResponse } from 'next'
2​
3// an simple endpoint for getting current list
4let list = ['Item 1', 'Item 2', 'Item 3']
5​
6export default async (
7 req: NextApiRequest,
8 res: NextApiResponse<typeof list>,
9) => {
10 const { add, clear } = req.query
11​
12 if (typeof add === 'string' && add) {
13 if (!list.includes(add)) {
14 list.push(add)
15 }
16 } else if (clear) {
17 list = []
18 }
19​
20 await new Promise((r) => setTimeout(r, 100))
21​
22 res.json(list)