Skip to content

Commit

Permalink
feat: add abort signal for both fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed Dec 3, 2024
1 parent f73e9be commit c7b4372
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export async function handleApiRequest(request: Request, url: URL) {
request.headers.set("Host", "discord.com");

if (request.method !== "GET" && request.method !== "HEAD") {
return fetch(url.toString(), {
method: request.method,
headers: request.headers,
body: request.body,
return fetch(url, {
...request,
signal: AbortSignal.timeout(10_000),
});
}
Expand Down Expand Up @@ -47,10 +45,9 @@ export async function handleApiRequest(request: Request, url: URL) {
}

async function makeRequest(cacheKey: bigint, url: URL, request: Request) {
const response = await fetch(url.toString(), {
method: request.method,
headers: request.headers,
body: request.body,
const response = await fetch(url, {
...request,
signal: AbortSignal.timeout(10_000),
});

const content =
Expand Down

0 comments on commit c7b4372

Please sign in to comment.