Skip to content

Commit

Permalink
fix(fetch): add headers to server fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Apr 3, 2024
1 parent 83f7dae commit d2004e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/lib/functions/fetchPublicResultsJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export async function fetchPublicResultsJSON(params: URLSearchParams): Promise<R

let response: Response;
try {
response = await fetch(apiUrl);
response = await fetch(apiUrl, {
method: 'GET' // POST doesn't cache on CDN
// no need for headers since it runs in the browser
});
} catch (err: any) {
// Service Unavailable
throw error(503, `Failed to fetch results: ${err.message}`);
Expand Down
9 changes: 8 additions & 1 deletion src/lib/functions/fetchResultsJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export async function fetchResultsJSON(

let response: Response;
try {
response = await fetch(apiUrl);
response = await fetch(apiUrl, {
// must set headers since it runs on the server
method: 'GET', // POST doesn't cache on CDN
headers: {
Accept: 'application/json',
'Accept-Encoding': 'gzip, deflate, br'
}
});
} catch (err: any) {
await delayed;
// Service Unavailable
Expand Down

0 comments on commit d2004e4

Please sign in to comment.