mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
18 lines
490 B
TypeScript
18 lines
490 B
TypeScript
import type { DelayMode } from 'msw'
|
|
import { http, delay, HttpResponse } from 'msw'
|
|
import { setupWorker } from 'msw/browser'
|
|
|
|
const worker = setupWorker(
|
|
http.get('/delay', async ({ request }) => {
|
|
const url = new URL(request.url)
|
|
const mode = url.searchParams.get('mode') as DelayMode
|
|
const duration = url.searchParams.get('duration')
|
|
|
|
await delay(duration ? Number(duration) : mode || undefined)
|
|
|
|
return HttpResponse.json({ mocked: true })
|
|
}),
|
|
)
|
|
|
|
worker.start()
|