fix baseAPIUrl to use reverse proxy

This commit is contained in:
Clément Le Bihan
2023-01-26 17:42:13 +09:00
parent b2cdfd32d4
commit b2bbf76705
+5 -1
View File
@@ -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'