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/dockerfiles/prod.Dockerfile b/dockerfiles/prod.Dockerfile index 9210a8f..84f7180 100644 --- a/dockerfiles/prod.Dockerfile +++ b/dockerfiles/prod.Dockerfile @@ -7,6 +7,7 @@ RUN npm config set registry http://192.168.31.115:8081/repository/npm/ RUN npm install -g expo-cli && npm install COPY . . RUN cp .env.production .env +ENV API_ENDPOINT=https://api.memorywake.com/api RUN npx expo export -p web # 第二阶段:使用 nginx 作为 Web 服务器 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,