-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy path+server.ts
More file actions
30 lines (28 loc) · 666 Bytes
/
+server.ts
File metadata and controls
30 lines (28 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
export async function GET({ url }) {
const delay = url.searchParams.get('delay') || '1'
const start = Date.now()
try {
const response = await fetch(`https://httpbin.org/delay/${delay}`)
const elapsed = Date.now() - start
return new Response(
JSON.stringify({
requestedDelay: delay,
elapsedMs: elapsed,
status: response.status
}),
{
headers: { 'content-type': 'application/json' }
}
)
} catch (error) {
return new Response(
JSON.stringify({
error: error instanceof Error ? error.message : String(error),
elapsedMs: Date.now() - start
}),
{
headers: { 'content-type': 'application/json' }
}
)
}
}