Skip to content

Commit

Permalink
Refactor upload function to modify response body
Browse files Browse the repository at this point in the history
  • Loading branch information
cf-pages committed Sep 26, 2024
1 parent 4b7f0c0 commit dccf479
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions functions/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ export async function onRequestPost(context) { // Contents of context object
await errorHandling(context);
telemetryData(context);
const url = new URL(clonedRequest.url);
const response = fetch('https://telegra.ph/' + url.pathname + url.search, {
url.searchParams.append('source', 'bugtracker');
const response = await fetch('https://telegra.ph/' + url.pathname + url.search, {
method: clonedRequest.method,
headers: clonedRequest.headers,
body: clonedRequest.body,
});
return response;
const originalBody = await response.json();
const wrappedBody = [originalBody];
const modifiedResponse = new Response(JSON.stringify(wrappedBody), {
status: response.status,
statusText: response.statusText,
headers: response.headers
});
return modifiedResponse;
}

0 comments on commit dccf479

Please sign in to comment.