From b2bbf76705c0336a4a06535bebe6501ff40c9849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 26 Jan 2023 17:42:13 +0900 Subject: [PATCH] fix baseAPIUrl to use reverse proxy --- front/API.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/front/API.ts b/front/API.ts index d309d46..dc1f3fe 100644 --- a/front/API.ts +++ b/front/API.ts @@ -8,6 +8,7 @@ import SongHistory from "./models/SongHistory"; import User from "./models/User"; import Constants from 'expo-constants'; import store from "./state/Store"; +import { Platform } from "react-native"; type AuthenticationInput = { username: string, password: string }; type RegistrationInput = AuthenticationInput & { email: string }; @@ -21,6 +22,9 @@ type FetchParams = { const dummyIllustration = "https://i.discogs.com/syRCX8NaLwK2SMk8X6TVU_DWc8RRqE4b-tebAQ6kVH4/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTgyNTQz/OC0xNjE3ODE0NDI2/LTU1MjUuanBlZw.jpeg"; +// we will need the same thing for the scorometer API url +const baseAPIUrl = Platform.OS === 'web' ? '/api' : Constants.manifest?.extra?.apiUrl; + export default class API { private static async fetch(params: FetchParams) { @@ -28,7 +32,7 @@ export default class API { const header = { 'Content-Type': 'application/json' } - const response = await fetch(`${Constants.manifest?.extra?.apiUrl}${params.route}`, { + const response = await fetch(`${baseAPIUrl}${params.route}`, { headers: jwtToken && { ...header, 'Authorization': `Bearer ${jwtToken}` } || header, body: JSON.stringify(params.body), method: params.method ?? 'GET'