diff --git a/.env b/.env index 53a6945..a102646 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -API_ENDPOINT=http://192.168.31.115:18080/api \ No newline at end of file +API_ENDPOINT=https://api.memorywake.com/api \ No newline at end of file diff --git a/app.config.js b/app.config.js index 5c730f6..aee3564 100644 --- a/app.config.js +++ b/app.config.js @@ -1,6 +1,4 @@ // app.config.js -console.log("API_ENDPOINT from process.env:", process.env.API_ENDPOINT); - export default ({ config }) => ({ ...config, extra: { diff --git a/lib/server-api-util.ts b/lib/server-api-util.ts index 7793c1c..5f9d009 100644 --- a/lib/server-api-util.ts +++ b/lib/server-api-util.ts @@ -1,4 +1,5 @@ import { setCredentials } from '@/features/auth/authSlice'; +import Constants from 'expo-constants'; import * as SecureStore from 'expo-secure-store'; import { Platform } from 'react-native'; import Toast from 'react-native-toast-message'; @@ -24,7 +25,7 @@ export interface PagedResult { // 获取.env文件中的变量 -export const API_ENDPOINT = () => process.env.API_ENDPOINT || "http://192.168.31.115:18080/api"; +export const API_ENDPOINT = () => Constants.expoConfig?.extra?.API_ENDPOINT || "http://192.168.31.115:18080/api"; // 更新 access_token 的逻辑 - 用于React组件中 export const useAuthToken = async(message: string | null) => { @@ -140,7 +141,7 @@ export const fetchApi = async ( headers.set('Authorization', `Bearer ${token}`); } - const url = `${API_ENDPOINT()}/v1${path}`; + const url = `${API_ENDPOINT}/v1${path}`; const response = await fetch(url, { ...options, headers,