Skip to content

Commit a72189f

Browse files
Temporarily removes Content-Type header from GET requests (#57)
Addresses an issue where the API server rejects GET requests containing a 'Content-Type: application/json' header. This is a temporary workaround to ensure compatibility with the current stac-react implementation and the API server's requirements. Once stac-react is updated to handle headers correctly, this workaround will be removed.
1 parent 666ad8c commit a72189f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/client/src/main.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,28 @@ Object.defineProperty(Array.prototype, 'last', {
8181
},
8282
set: undefined
8383
});
84+
85+
// 😱😱😱😱😱😱😱
86+
//
87+
// stac-manager relies on stac-react for making STAC API requests.
88+
// Currently, stac-react adds a 'Content-Type: application/json' header to all
89+
// requests, including GET requests. However, the api server rejects GET
90+
// requests with this header. Ideally, the server should accept this header, but
91+
// as a workaround, we remove it from GET requests to avoid server errors. This
92+
// is a temporary fix is just to get things working while stac-react is updated.
93+
// I promise it is temporary!
94+
const fetch = window.fetch;
95+
window.fetch = (async (input: RequestInfo, init?: RequestInit) => {
96+
// If is a GET request, without body, remove the Content-Type header.
97+
if (
98+
init &&
99+
(!init.method || init.method.toUpperCase() === 'GET') &&
100+
!init.body &&
101+
// @ts-expect-error Content-Type can be a header property
102+
init.headers?.['Content-Type']
103+
) {
104+
// @ts-expect-error Content-Type can be a header property
105+
delete init.headers['Content-Type'];
106+
}
107+
return fetch(input, init);
108+
}) as typeof window.fetch;

0 commit comments

Comments
 (0)