Fix Android emulator dev server: use 10.0.2.2 instead of localhost
Android emulator has its own network stack — localhost refers to the emulator, not the host. Use 10.0.2.2 (host loopback alias) on Android. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b2514f48be
commit
6c55de9d65
2 changed files with 7 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { View, Text, TextInput, TouchableOpacity, StyleSheet, ActivityIndicator } from "react-native";
|
import { View, Text, TextInput, TouchableOpacity, StyleSheet, ActivityIndicator, Platform } from "react-native";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import {
|
import {
|
||||||
setServerUrl,
|
setServerUrl,
|
||||||
|
|
@ -9,9 +9,11 @@ import {
|
||||||
} from "../lib/server-config";
|
} from "../lib/server-config";
|
||||||
import { login } from "../lib/auth";
|
import { login } from "../lib/auth";
|
||||||
|
|
||||||
|
const DEV_HOST = Platform.OS === "android" ? "10.0.2.2" : "localhost";
|
||||||
|
|
||||||
export default function LoginScreen() {
|
export default function LoginScreen() {
|
||||||
const [serverUrl, setServerUrlState] = useState(
|
const [serverUrl, setServerUrlState] = useState(
|
||||||
__DEV__ ? "http://localhost:3000" : "https://trails.cool",
|
__DEV__ ? `http://${DEV_HOST}:3000` : "https://trails.cool",
|
||||||
);
|
);
|
||||||
const [showCustomServer, setShowCustomServer] = useState(false);
|
const [showCustomServer, setShowCustomServer] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
|
import { Platform } from "react-native";
|
||||||
import * as SecureStore from "expo-secure-store";
|
import * as SecureStore from "expo-secure-store";
|
||||||
import { API_VERSION } from "@trails-cool/api";
|
import { API_VERSION } from "@trails-cool/api";
|
||||||
|
|
||||||
const STORE_KEY_SERVER_URL = "server_url";
|
const STORE_KEY_SERVER_URL = "server_url";
|
||||||
const DEFAULT_SERVER_URL = __DEV__ ? "http://localhost:3000" : "https://trails.cool";
|
const DEV_HOST = Platform.OS === "android" ? "10.0.2.2" : "localhost";
|
||||||
|
const DEFAULT_SERVER_URL = __DEV__ ? `http://${DEV_HOST}:3000` : "https://trails.cool";
|
||||||
|
|
||||||
export interface DiscoveryResponse {
|
export interface DiscoveryResponse {
|
||||||
apiVersion: string;
|
apiVersion: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue