Add API configuration for different platforms in frontend
This commit is contained in:
20
frontend/src/config/api.ts
Normal file
20
frontend/src/config/api.ts
Normal 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();
|
@ -1,9 +1,10 @@
|
||||
import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink } from '@apollo/client';
|
||||
import { setContext } from '@apollo/client/link/context';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { API_URL } from '../config/api';
|
||||
|
||||
const httpLink = createHttpLink({
|
||||
uri: 'http://localhost:3000/graphql', // Для эмулятора Android используйте 10.0.2.2 вместо localhost
|
||||
uri: API_URL,
|
||||
});
|
||||
|
||||
const authLink = setContext(async (_, { headers }) => {
|
||||
|
Reference in New Issue
Block a user