From 1ce6147da57bcf634a34dbd955fc57dc62358d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20L=C3=B6w?= Date: Mon, 16 Dec 2024 07:44:29 +0100 Subject: [PATCH] fix: :poop: on web, do not send user agent to anonymous THI API (because of their CORS policy) --- src/api/anonymous-api.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/anonymous-api.ts b/src/api/anonymous-api.ts index 59fe8a9a..5572e55a 100644 --- a/src/api/anonymous-api.ts +++ b/src/api/anonymous-api.ts @@ -1,3 +1,5 @@ +import { Platform } from 'react-native' + import packageInfo from '../../package.json' const ENDPOINT_HOST: string = 'hiplan.thi.de' @@ -31,12 +33,14 @@ export class AnonymousAPIClient { */ async request(params: Record): Promise { const apiKey = process.env.EXPO_PUBLIC_THI_API_KEY ?? '' - const headers = new Headers({ + const headersObj: Record = { Host: ENDPOINT_HOST, 'Content-Type': 'application/x-www-form-urlencoded', - 'User-Agent': USER_AGENT, 'X-API-KEY': apiKey, - }) + } + if (Platform.OS !== 'web') headersObj['User-Agent'] = USER_AGENT + + const headers = new Headers(headersObj) const resp = await fetch(`https://${ENDPOINT_HOST}${ENDPOINT_URL}`, { method: 'POST',