Add API configuration for different platforms in frontend

This commit is contained in:
Bivekich
2025-08-06 02:32:10 +03:00
parent 643a6b76b3
commit b75c866c5f
2 changed files with 22 additions and 1 deletions

View File

@ -0,0 +1,20 @@
import { Platform } from 'react-native';
// Определяем URL API в зависимости от платформы
const getApiUrl = () => {
if (__DEV__) {
// В режиме разработки
if (Platform.OS === 'android') {
// Для Android эмулятора
return 'http://10.0.2.2:3000/graphql';
} else {
// Для iOS симулятора и веб
return 'http://localhost:3000/graphql';
}
} else {
// В продакшене - укажите реальный URL вашего сервера
return 'https://api.prism-messenger.com/graphql';
}
};
export const API_URL = getApiUrl();

View File

@ -1,9 +1,10 @@
import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink } from '@apollo/client'; import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink } from '@apollo/client';
import { setContext } from '@apollo/client/link/context'; import { setContext } from '@apollo/client/link/context';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import { API_URL } from '../config/api';
const httpLink = createHttpLink({ const httpLink = createHttpLink({
uri: 'http://localhost:3000/graphql', // Для эмулятора Android используйте 10.0.2.2 вместо localhost uri: API_URL,
}); });
const authLink = setContext(async (_, { headers }) => { const authLink = setContext(async (_, { headers }) => {