Skip to content

Commit

Permalink
Merge pull request #204 from hearchco/as/fix/fetch-headers
Browse files Browse the repository at this point in the history
fix(fetch): add headers to server fetch
  • Loading branch information
aleksasiriski authored Apr 3, 2024
2 parents 270b725 + d2004e4 commit 908c5f1
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 908c5f1

Please sign in to comment.