Open History to see the last commit
1import { HttpResponse, delay, http } from 'msw'
2import { setupWorker } from 'msw/browser'
3β
4export const worker = setupWorker(
5 http.get('/api/projects', async ({ request }) => {
6 const cursor =
7 parseInt(new URL(request.url).searchParams.get('cursor') ?? '', 10) || 0
8 const pageSize = 5
9β
10 const data = Array(pageSize)
11 .fill(0)
12 .map((_, i) => {
13 return {
14 name: `Project ${i + cursor} (server time: ${Date.now()})`,
15 id: i + cursor,
16 }
17 })
18β
19 const nextId = cursor < 10 ? data[data.length - 1].id + 1 : null
20 const previousId = cursor > -10 ? data[0].id - pageSize : null
21β
22 await delay(1000)
23β
24 return HttpResponse.json({ data, nextId, previousId })
25 }),
26)