Skip to content

Commit

Permalink
fix: 💩 on web, do not send user agent to anonymous THI API (because o…
Browse files Browse the repository at this point in the history
…f their CORS policy)
  • Loading branch information
M4GNV5 committed Dec 16, 2024
1 parent a806afb commit 1ce6147
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/api/anonymous-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Platform } from 'react-native'

import packageInfo from '../../package.json'

const ENDPOINT_HOST: string = 'hiplan.thi.de'
Expand Down Expand Up @@ -31,12 +33,14 @@ export class AnonymousAPIClient {
*/
async request(params: Record<string, string>): Promise<any> {
const apiKey = process.env.EXPO_PUBLIC_THI_API_KEY ?? ''
const headers = new Headers({
const headersObj: Record<string, string> = {
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',
Expand Down

0 comments on commit 1ce6147

Please sign in to comment.