Skip to content

Commit

Permalink
Merge pull request #67 from Georiviere/accept_headers
Browse files Browse the repository at this point in the history
Add explicit "application/json" accept header to requests
  • Loading branch information
Bo-Duke authored Apr 24, 2024
2 parents 812a17d + 6cfdb16 commit 4b483c2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { getDetailsUrl } from './settings';
async function fetchDetails(url: string) {
const res = await fetch(`${process.env.apiHost}${url}`, {
next: { revalidate: 60 * 60 },
headers: {
Accept: 'application/json',
},
});
if (res.status < 200 || res.status > 299) {
throw new Error('Failed to fetch data');
Expand Down
3 changes: 3 additions & 0 deletions src/api/observations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ async function fetchObservation() {
`${process.env.apiHost}/api/portal/fr/${process.env.portal}/contributions/json_schema/`,
{
next: { revalidate: 60 * 60 },
headers: {
Accept: 'application/json',
},
},
);
if (res.status < 200 || res.status > 299) {
Expand Down
3 changes: 3 additions & 0 deletions src/api/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Menu, getMenuSettings } from './settings';
async function fetchDetails(url: string) {
const res = await fetch(`${process.env.apiHost}${url}`, {
next: { revalidate: 60 * 60 },
headers: {
Accept: 'application/json',
},
});
if (res.status < 200 || res.status > 299) {
throw new Error('Failed to fetch data');
Expand Down
3 changes: 3 additions & 0 deletions src/api/poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ async function fetchPois({ params }: FetchPoisProps = {}): Promise<Poi[]> {
const url = `${process.env.apiHost}/api/portal/fr/${process.env.portal}/pois/`;
const urlWithParams = [url, params].filter(Boolean).join('?');
const res = await fetch(urlWithParams, {
headers: {
Accept: 'application/json',
},
next: { revalidate: 60 * 60 },
});
if (res.status < 200 || res.status > 299) {
Expand Down
3 changes: 3 additions & 0 deletions src/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ export async function fetchSettings(): Promise<RawSettings> {
`${process.env.apiHost}/api/portal/fr/portal/${process.env.portal}/`,
{
next: { revalidate: 60 * 60 },
headers: {
Accept: 'application/json',
},
},
).catch(error => {
throw error;
Expand Down

0 comments on commit 4b483c2

Please sign in to comment.