diff --git a/frontend/src/config/api.ts b/frontend/src/config/api.ts new file mode 100644 index 0000000..024288f --- /dev/null +++ b/frontend/src/config/api.ts @@ -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(); \ No newline at end of file diff --git a/frontend/src/services/apollo-client.ts b/frontend/src/services/apollo-client.ts index 908ba43..2d9c2c0 100644 --- a/frontend/src/services/apollo-client.ts +++ b/frontend/src/services/apollo-client.ts @@ -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 }) => {